Chazin Home Chazin Home | Ca-binding Protein DB | Vanderbilt Home Vanderbilt Home
Research Description | Publications | Wisdom | Search
How to contribute | About this page

Randy's UNIX Tips

collected and edited by Randal R. Ketchem
last updated Tue Jun 25 17:27:22 PDT 1996

These tips have been added as I have discovered them over the years, so they aren't yet catagorized. Search for a topic to find occurrences.

----------
To copy fields 3 and 7 from input to output (3 string, 7 float):
   awk '{printf"%s\t%10.4f\n", $3, $7}' < input > output
----------
To add a column of numbers:
   awk '{sum=sum+$1;printf("sum: %d\n", sum)}' < input | tail -1
----------
To calc the average of numbers in a file:
   egrep "^:2" *out | egrep total | cut -c44- | \
      awk '{sum += $1;total += 1;printf"avg = %.4f\n", sum/total}' | \
      tail -1
----------
To find 'word' in files owned by 'username' from location '.':
   find . -user username -print -exec \grep word '{}' \; > output &
----------
To find all files that do not end in 'pdb' in location '.':
   find . \( ! -name \*pdb \) -print
----------
To find all files that do not end in 'pdb' in location '.' and execute a
command on each file found:
   find . \( ! -name \*pdb \) -exec \anneal2pdb '{}' \;
----------
To remove all files 'garb':
   find ~ -name garb -print -exec \rm '{}' \;
----------
To report the file size of all files bigger than 2 meg and older than 30
days.
   find . -type f -size +4096 -atime +30 -exec \du -sk '{}' \;
----------
To search with a wildcard:
   find . -name goob\* -print
----------
To manually nudge NFS:
   umount /iris1/a (or whatever)
   mount -a -t nfs
   exportfs -a -v
----------
To encrypt the file 'input' to a file 'output':
   crypt < input > output
   enter key: (enter a password)
To decrypt the file 'output' to a file 'done':
   crypt < output > done
   enter key: (enter the password used to encrypt 'output')
----------
To convert tabs to spaces:
   expand -tabstop filename.in > filename.out
   eg
      expand -3 garb > garb.out
      will convert tabs to three spaces

To convert spaces to tabs:
   unexpand filename
----------
To check the print que:
   lpq
To remove a print job:
   lprm <job # from lpq>
To check the printer:
   lpc
----------
To remove duplicate lines from a file:
   uniq filename > out
----------
To mail to compuserve:
   If the username is '70000,200', mail to:
   mail 70000.200@compuserve.com
   note the period instead of the comma.
To mail from compuserve:
   >INTERNET Loopy@cup.portal.com
----------
To create a text file from a manual page:
   man command | expand > file
   vi file
   :1,$s/.^V^H//g
   :x
----------
To compare two files:
   Flags 1, 2, or 3 suppress printing of the corresponding column.  Thus
   comm -12 prints only the lines common to the two files; comm -23 prints
   only lines in the first file but not in the second; comm -123 prints
   nothing.
----------
To run a string of commands over and over:
   csh> sh
   $ while :
   > do
   > command
   > command
   > done
When done, ^C to quit. ^D to return to csh.
----------
To get a list of 'fsu.edu' machines:
   UNIX> nslookup
   > ls fsu.edu > file
   > exit
----------
To get a machine name from an IP address:
   UNIX> nslookup
   > set type=ptr
   > 34.12.186.128.in-addr.arpa
   Server:  magnet.fsu.edu
   Address:  146.201.250.2

   34.12.186.128.in-addr.arpa      name = weirdscience.chem.fsu.edu
----------
To add line numbers to the beggining of a file:
   grep -n . input > output
      or
   paste x y > z
----------
To move (or copy) a directory heirarchy:
   cd fromdir
   tar cf - . | (cd todir; tar xfBp -)
----------
To copy a directory heirarchy exactly:
   cd fromdir; tar cBf - . | (cd todir; tar xpBf -)
----------
To restart the sendmail process:
   kill the original process
   /usr/lib/sendmail -bd -q1h
----------
To alias rm so that it lists the files to be removed and asks for
confirmation:
   alias rm \
   '/bin/ls -AsF \!* && echo -n "Remove? " && if ($< == y) /bin/rm -rf \!*'
----------
To remove blank lines from a file:
   sed -e '/^$/d' file.in > file.out
----------