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.

Commands you should know

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.

Network tools

  • 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

Other programs

  • ispell/aspell - spell checkers
  • dict - dictionary tool

Simple command line tips

  • How to run a command to a set of files (The while read command can handle names with spaces but you need to quote the variable after):
[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
  • How to rename part of a file:
[unix]$ echo filename | sed 's/file/another/'
  • How to replace text in multiple files:
[unix]$ sed -e 's/oldtext/newtext/' -i file1 file2 file3 ...
  • How to delete lines matching a pattern in some files:
[unix]$ sed -e '/pattern/ d' -i file1 file2 file3 ...
  • How to change all letters to lowercase:
[unix]$ echo FilENamE | tr A-Z a-z
  • A good way to change all filenames in a directory to lowercase:

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
  • How to convert man pages to text files:
[unix]$ man man | col -b
  • How to list all the open ports and programs:
[linux]$ netstat -apne --inet
[freebsd]$ sockstat
  • How to list all the open files and programs:
[linux]$ lsof
[freebsd]$ fstat
  • How to find information about an ip (i.e.
[unix]$ host
[unix]$ dig -x
  • How to find information about an ip owner (i.e.
[unix]$ whois -h whois.arin.net
  • How to find out the mailserver for an ip:
[unix]$ dig mx some.domain.name.net
  • How to generate a filename with yesterdays date (i.e. for logfiles/backups):
[linux]$ touch logfile-`date -dyesterday '+%Y-%m-%d'`
[freebsd]$ touch logfile-`date -v-1d '+%Y-%m-%d'`
technology/unix/nachokb.txt · Last modified: 01.25.2009 13:32 by
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki