Shell Cheatsheet

I am by no means a UNIX poweruser so I routinely find myself searching for various command line tools that may be useful even on Mac OS for specific tasks. This article is something of a cheat sheet for myself where I can collect and annotate different useful shell programs and commands. Manpages are all fine and dandy, but if you don’t know which commands exist in the first place, they don’t get you anywhere, hence this list.

df — Ancient UNIX command. Basically gives you a quick tabular overview of your mounted filesystems and their free space:

macbookpro:~ johndoe$ df

Filesystem 512-blocks    Used Available Capacity  iused  ifree %iused Mounted on
/dev/disk0s2  3905349 2126435   1778402      55% 265868 222300    54% /
devfs             655     655         0     100%   1136      0   100% /dev
map -hosts          0       0         0     100%      0      0   100% /net
map auto_home       0       0         0     100%      0      0   100% /home
map -fstab          0       0         0     100%      0      0   100% /Network/Servers

top — Outputs a live table showing the currently running processes:

Processes: 365 total, 6 running, 16 stuck, 343 sleeping, 1993 threads  19:19:48
Load Avg: 12.88, 11.42, 8.50  CPU usage: 86.61% user, 12.87% sys, 0.51% idle
SharedLibs: 177M resident, 22M data, 16M linkedit.
MemRegions: 80849 total, 6636M resident, 186M private, 1069M shared.
PhysMem: 16G used (1601M wired), 33M unused.
VM: 1024G vsize, 535M framework vsize, 0(0) swapins, 1216(0) swapouts.
Networks: packets: 1953271/2529M in, 1259576/132M out.
Disks: 1701576/43G read, 662431/28G written.

PID    COMMAND      %CPU  TIME     #TH   #WQ  #PORT MEM    PURG   CMPRS  PGRP
15105  com.apple.au 0.0   00:00.14 2     1    34    1880K  0B     0B     15105
15104  com.apple.au 0.0   00:00.03 2     1    24    1088K  0B     0B     15104
15068  VTDecoderXPC 0.0   00:00.16 2     0    39    16M    0B     0B     15068
15067  com.apple.au 0.0   00:00.10 2     1    34    1804K  0B     0B     15067
15066  com.apple.au 0.0   00:00.12 2     1    34    1848K  0B     0B     15066
15065  com.apple.au 0.0   00:00.03 3     2    25    1076K  0B     0B     15065
15064  com.apple.au 0.0   00:00.02 2     1    24    1100K  0B     0B     15064
15063  QuickLookSat 0.0   00:00.25 2     0    49    4576K  624K   0B     15063
15060  top          18.2  00:10.71 1/1   0    29    3596K  0B     0B     15060
15050  postgres_rea 0.0   00:00.01 1     0    7     1052K  0B     0B     15050
15045  postgres_rea 0.0   00:00.01 1     0    7     2144K  0B     0B     15045
15044  mdworker     0.0   00:00.06 3     0    38    3064K  0B     0B     15044
15043  mdworker     0.0   00:00.07 3     0    38    3112K  0B     0B     15043
15039  postgres_rea 0.0   00:00.02 1     0    7     568K   0B     0B     15039

Optionally you can order the list differently, maybe you want to see which processes use the most memory:

macbookpro:~ johndoe$ top -o rsize

fs_usage

macbookpro:~ johndoe$ fs_usage

less — Paginates text input into it into manageable scrollable output. Use it by pipeing output from another command into it with |. Scroll with the arrow buttons, or faster with the page up and down buttons. Quit by hitting q.

macbookpro:~ johndoe$ sudo fs_usage | less