Ten UNIX Commands Every Geek Should Know

Peter Karman

http://svn.peknet.com/perl/slides/ten-unix-commands

1. kill

# stop a process with pid 1234
% kill 1234

# stop a process with pid 1234, please
% kill -1 1234

# c'mon, die already
% kill -15 1234

# die! die! damn you!!
% kill -9 1234
      

2. ps

# what processes are mine
% ps -ef | grep `whoami`

# what apache processes are running
% ps -ef | grep http
     

3. top

% top
# 'q' to quit

# on Linux, can sort by column while running
% top
# 'M' sorts by memory use
     
     

4. grep

# search inside all files, recursively, case-insensitive
# and skip all .svn files
% grep -r -i 'foo' . | grep -v .svn

# search the output of another command
% ls -1 | grep .pdf

# output only matching file names
% grep -r -i -l 'foo' .
     

5. find

# all files with .pdf extension
% find . -name '*.pdf'

# all files you own
% find . -uid `whoami`

# all directories, not files
% find . -type d

# all files, not directories
% find . -type f
    

6. xargs

# change permissions for all files, skipping dirs
% find . -type f | xargs chmod 664

# change permissions for all dirs, skipping files
% find . -type d | xargs chmod 775

    

7. watch

# real-time dismay as your disk fills up
% watch df -h

# ctrl-C to quit
     

8. tail

# watch a log file
% tail -f /path/to/apache/error_log

# watch a log file for particular pattern
% tail -f /path/to/busy/apache/access_log | grep 404
    

9. more (or less)

# read a file, a little at a time
% more path/to/file

# space bar to advance a page, 
# return to advance a line,
# 'q' to quit

    

10. perl

# find and replace a string, creating a backup first
% perl -pi.backup -e 's/before/after/g' file

# iterate over all input, mangling certain lines
% tail -f path/log | \
  perl -n -e 'if (m/404/) { print "found $_" }'

    

11. man

# search for keywords in man page whatis file
% man -k search

# read the man man page
% man man

# the location of the man page
% man -w grep

# the system call, not user command
% man 2 kill

    

etc

nohup, ctrl-Z, fg, bg, disown
ssh
vi
cat
echo
df
du
sort
date
gzip
tar
netstat
dig
telnet
chmod, chown, chgrp