Interesting Unix Commands

This is a small list of commands that I have found useful over the years of system administration and software development.

Vim

Set printer font
set pfn=:h8
Change case (lower and upper, respectively)
ggguG
gggUG
Force save file as root

This is for those times when you've opened an OS configuration file as yourself, made many (or not) changes, then realized that you aren't root.

:w !sudo tee %
Delete trailing whitespace from file
:%s/\s\+$
Delete blank lines
:g/^$/d
Show code of character under cursor
:h \%x
Search for whole words
\<word\>
Join entire file, remove CRLFs
%join

System Adminstration

TCP Port and IP Address Listeners
  • Solaris and MacOS X

    sudo lsof -i -n -P | grep TCP
    
  • Linux

    sudo netstat -plunt
    
Make ISO Disk Image (MacOS X)

Create a disk image (suitable for burning to CD) of the contents of srcdir/.

hdiutil makehybrid -o f.iso -hfs -joliet -iso srcdir/
Mac DNS Cache Flush

The dscacheutil command alone used to work in 10.6, but the later versions (I can't say definitively for 10.7 because I skipped-over it) also require HUP-ing the mDNSResponder daemon. To flush the DNS cache on a Mac:

$ dscacheutil -flushcache
$ sudo killall -HUP mDNSResponder