List (ls)

Usage

ls [options] [paths]

Format

SwitchDescription
-1One entry per line
-lLong view
-oLong view (without groups)
-CMulticolumn (sorted horizontally)
-xMulticolumn (sorted vertically)
-FAdd / after directories
-GColor

Options

SwitchDescription
-RRecurse
-aInclude hidden (dotfiles)
-AInclude hidden (but not . and ..)

Sorting

SwitchDescription
-rreverse order
-Ssort by size
-tsort by time modified
-usort by time accessed
-Usort by time created
-csort by time status was changed
-hHuman-readable size (3k)

Tail

Usage

tail [-F | -f | -r] [-bN | -cN | -nN] [file ...]

Modes

ModeDescription
-ffollow
-Ffollow by filename (accounts for log rotation)
-rReverse order

Options

OptionDescription
-bNN*512 bytes
-cNN bytes
-nNN lines
+NStart from line N

Sudo

Usage

sudo [options] <command>

Listing

OptionDescription
-lList allowed commands

Options

OptionDescription
-AUse $SUDO_ASKPASS
-bRun in background
-EPreserve environment
-Huse target's $HOME
-nDon't prompt for password
-PPreserve group vector
-SRead password from stdin

File descriptors

OptionDescription
-C fdClose all open file descriptors

Prompt

OptionDescription
-p promptCustom prompt (-p "%p password:")

Interactive

SwitchDescription
-i [cmd]Interactive shell without variables
-s [cmd]Interactive shell
-u userrun as this user
-g grouprun as this group

Timestamp

OptionDescription
-vrevalidate timestamp for 5 mins
-kinvalidate timestamp
-Kjust like -k

wc (Word count)

wc

... | wc [options]

Options

OptionDescription
-cBytes
-lLines
-mCharacters (incl multi-byte)
-wWords

Grep

Usage

grep [options] [pattern] [file ...]

Options

SwitchDescription
-A numPrint num lines of training context
-G--basic-regexp (default)
-E--extended-regexp
-P--perl-regexp
-f file--file (Get patterns for file)
-F--fixed-strings
-h--no-filename
-H--with-filename
-l--files-with-matches (just print filenames)
-L--files-without-match
-r, -R--recursive
-v--invert-match
-i--ignore-case

Synonyms

egrep  =>  grep -E
fgrep  =>  grep -F

Other recipes

Search-and-replace in all files

perl -p -i -e 's/hello/HELLO/g' **/*
0 Comments for this cheatsheet. Write yours!