Recent Notes
Displaying keyword search results 1 - 11
Created by voodoo on March 24, 2013 13:44:47
Last update: March 29, 2013 13:08:31
Use getpwnam group of functions. Example code:
#include <sys/types.h>
#include <pwd.h>
#inc...
For gid, use getgrnam
Created by magnum on October 22, 2012 19:48:03
Last update: October 22, 2012 19:48:03
execl takes the full path name of the command and variable length of arguments terminated by NULL:
execl("/bin/ls", "/bin/ls", "-r", "-t", "-l", NULL...
where the second argument is argv[0] , but can be any string!
execlp will try to find the command from $PATH , so full path to command is not needed:
execl("ls", "ls", "-r", "-t", "-l", NULL);
execv is the equivalent of execl , except that the arguments are passed in as a NULL terminated array:
char *args[] = {"/bin/ls", "-r", "-t", "-l", NULL ...
execvp is the equivalent of execvl , excep that the arguments are passed in as a NULL terminated array:
char *args[] = {"ls", "-r", "-t", "-l", NULL };
...
Created by voodoo on December 08, 2011 08:52:40
Last update: December 08, 2011 08:52:40
I don't know if there's a fool proof way to find out which Linux distro you are running on, but here are some ways you can try:
cat /proc/version
cat /etc/issue
cat /etc/*release
lsb_release -a
Results on Ubuntu 11.10 oneiric:
$ cat /proc/version
Linux version 3.0.0-13-gene...
Results on Red Hat Enterprise Server:
$ cat /proc/version
Linux version 2.6.18-128.1....
Created by voodoo on November 22, 2011 12:27:12
Last update: November 22, 2011 12:31:50
Unix hidden files are named starting with a dot ".".
To find hidden files in the current directory:
$ find . -type f -name '.*'
or
$ find . -type f | grep \\/\\.
To find hidden files in the marketing directory:
$ find marketing -type f -name '.*'
or
$ find marketing -type f | grep \\/\\.
Created by Dr. Xi on September 30, 2011 15:34:47
Last update: September 30, 2011 15:34:47
A naive try would be something like this:
$ nc -l 8082 | nc remote_host 80 Yes, it does forward the request from local port 8082 to remote_host:80 , but the response is dumped to stdout , not routed back to the client as expected. Using a named pipe makes it work: $ mkfifo backpipe $ nc -l 8082 0<backpipe | nc ... Use tee to get a glimpse of the response through the pipe (I wasn't able to find a way to dump the request): $ nc -k -l 8082 0<backpipe | nc localhost 80 | tee... The GNU netcat has a different syntax than the stock nc . It also supports different switches. To listen to port 1234: $ netcat -l -p 1234...
Created by magnum on September 27, 2011 12:55:51
Last update: September 27, 2011 12:55:51
These steps set up a Linux host as IPSec client, using Openswan .
Install Openswan:
# yum install openswan
Edit /etc/ipsec.conf . Instead of L2TP on port 1701, I'm setting up TCP on port 8080 so that I can test the connection with nc .
# /etc/ipsec.conf - Openswan IPsec configuration f...
Edit /etc/ipsec.secrets .
# include /etc/ipsec.d/*.secrets
192.168.0.101 ...
Start IPSec:
# /etc/init.d/ipsec start
Connect to IPSec server:
# ipsec auto --up TCP8080-PSK-CLIENT
104 "TCP80...
Created by magnum on May 06, 2011 12:26:14
Last update: May 06, 2011 12:26:14
The bash environment variable PROMPT_COMMAND contains a regular bash command that is executed just before the command prompt is displayed.
For example:
$ export PROMPT_COMMAND=a
bash: a: command not ...
The command a is not valid so you get the error message every time you hit enter.
Echo something before $PS1 :
$ export PROMPT_COMMAND='echo -n Hi!'
Hi!$
...
PROMPT_COMMAND is regularly used to change the xterm window title. You may find this in /etc/bashrc :
case $TERM in
xterm*)
if [ -...
Created by magnum on March 09, 2011 15:49:58
Last update: March 09, 2011 15:49:58
GNU cpio copies files into or out of a cpio or tar archive. There are 3 modes:
-o : copy-out mode, copies files into an archive
-i : copy-in mode, copies files out of an archive
-p : copy-pass mode, combines the copy-out and copy-in steps without actually using an archive
Examples:
# create a cpio archive with all files in the ...
Created by mak on March 03, 2011 15:36:08
Last update: March 03, 2011 15:36:08
This worked:
gcc hello.c
But this failed:
gcc -static hello.c
/usr/bin/ld: cannot find -l...
I was missing static glibc libraries. Installed the static libraries with:
yum install glibc-static
Verify with ldd :
ldd a.out
not a dynamic executable
Created by Dr. Xi on February 11, 2010 05:07:48
Last update: February 11, 2010 05:08:20
On Linux, you can use the fuser command to find out who has a file open, or is using a port. For example, if you start Tomcat and get the error "Address already in use: 8080", you want to know which process is already binding to port 8080.
# list processes on port 8080
fuser 8080/tcp
...
Created by Dr. Xi on August 21, 2007 03:11:20
Last update: August 21, 2007 03:45:18
I was experiencing extreme slow DNS lookup on my wireless network when using Firefox on my FC4 installation. I found some discussions on the Apple discussion group and the Fedora forum but I wasn't able to find much help for my situation. I then looked at the DNS entries configured by the DHCP service and it was listing the IP addresses of my wireless router and DSL modem. I disabled automatic DNS setup and manually entered the name servers in /etc/resolv.conf . It's now much faster. I booted my laptop to Windows, the DHCP assigned DNS entries remained the same (wireless router and DSL modem). But I didn't have any problems with either Firefox or IE. This seems to be a Linux (maybe FC4?) only