Mirror from http://www.igso.net/nkb/Unix_Tips
These are some simple things, don’t expect anything fancy. Also, realize that most of these things can be done multiple ways and with multiple languages. Sometimes to achieve the effect you desire you’ll need to combine them or add extra code.
You should know, or at least be aware of all these commands. You don’t need to memorize their usage, you can always read the man pages.
tail - display the end of a file
head - display the beggining of a file
xargs - convert stdin to command line arguments
nmap - network scanner
watch (linux) - run a command periodically and watch the output
watch (freebsd) - monitor a tty
lsof - lists the open files
strace (linux) - trace the system calls of a program
truss (freebsd) - trace the system calls of a program
calc - command line calculator program
bc - another command line calculator program
dc - command line RPN calculator program
du - how much disk space is being used by something
df - disk free, how much free space there is
touch - creates an epty file or updates the timestamp on a file
diff - show the difference between 2 files
strings - show the strings in a file (useful for binaries)
file - tells you what type a file is
finger - find out information about users
w / who - who is currently on the machine and what are they doing
id - tells you who you are
uname - tells you basic information about the system.
whois - information about hosts
crontab - execute commands at specified times
last - last users to log into the system
mail - very basic mailer, useful for redirection
nice/renice - set the niceness (”priority”) level of a program
nohup - leave a program running after logging off
screen - virtual terminal for leaving programs running
psnup - print multiple pages in one page
time - time the execution of a command
wc - word count, tells you the size in bytes, words and lines
which / whereis - locates commands
locate - locates files
whatis - gives brief summary of a command
wget / fetch - get files off the net
talk - chat with other users on the system
write / wall - send messages to users of the system
zcat - cat gzipped files
ln - link files
sleep - wait a specified amount of time
md5sum (linux) - calculate the md5 signature of a file
md5 (freebsd) - calculate the md5 signature of a file
enscript - convert text files to ps
awk, sed - useful scripting programs
cat, echo, more/less, find, grep - you need to know these, it’s not an option.
netstat - network information
ping - check if hosts are up
tcpdump - look at the traffic going through the network
nmap - scan hosts
finger - see info about remote users
whois - get info about hosts
ifconfig - configure interfaces
ifup/ifdown - script/program to enable interfaces
[unix]$ for i in `ls *mp3`; do cp $i $i.bak; done
[unix]$ ls *mp3 | while read i; do cp "$i" "$i with more spaces"; done
[unix]$ echo filename | sed 's/file/another/'
[unix]$ sed -e 's/oldtext/newtext/' -i file1 file2 file3 ...
[unix]$ sed -e '/pattern/ d' -i file1 file2 file3 ...
[unix]$ echo FilENamE | tr A-Z a-z
This handles a colored ls (hence the quotes around ls), but you can use any file list output (e.g. find) and names with spaces (hence the while read
and not the for
).
[unix]$ "ls" | while read name; do mv "$name" "`echo $name | tr A-Z a-z`"; done
[unix]$ man man | col -b
[linux]$ netstat -apne --inet
[freebsd]$ sockstat
[linux]$ lsof
[freebsd]$ fstat
[unix]$ host 10.0.0.0
[unix]$ dig -x 10.0.0.0
[unix]$ whois -h whois.arin.net 10.0.0.0
[unix]$ dig mx some.domain.name.net
[linux]$ touch logfile-`date -dyesterday '+%Y-%m-%d'`
[freebsd]$ touch logfile-`date -v-1d '+%Y-%m-%d'`