Linux Cheat Sheet

Working with Files

pwd
print working directory
ls [options] [file ...]
list directory contents; options:
  • -a don't ignore names that begin with a dot
  • -l list in long format
  • -S sort by size, largest first
  • -t sort by time modified, most recent first
  • -r reverse sort order
cd [dir]
change working directory; shortcuts:
  • . current directory
  • .. parent directory
  • ~ your home directory
  • ~user user's home directory
mkdir directory ...
make directories
mv source target
rename source to target
mv source ... directory
relocate each source into directory.
cp [options] source ... target
copy each source into target
cp [options] source ... target
copy each source into target
rm [options] file ...
remove each file; options:
  • -d remove empty directories
  • -r remove files and directories recursively
  • -f do not prompt for confirmation, DANGEROUS
cat [file ...]
concatenate each file and print to screen
head [-N] [file ...]
display first N (default 10) lines of each file
tail [-N] [file ...]
display last N (default 10) lines of each file

Informative Commands

date
display date and time
whoami
show your user id
uptime
show system uptime and load
history
show your recent commands

Keyboard Shortcuts

To type C-a, hold Control while typing A.

To type M-a, hold Alt while typing A,
or tap Escape then type A.

    these are essentially the same keybindings as those of Emacs.
  • C-a jump to beginning of line
  • C-e jump to end of line
  • C-k delete to end of line
  • C-u delete to start of line
  • C-w delete previous word
  • C-y insert last deleted text
  • C-r interactively search previous commands
  • C-c interrupt current command
  • C-z suspend current command (resume with fg)
  • C-d delete character forward; or, end of input
  • M-d delete word forward
  • or C-p previous line entered
  • or C-n next line entered
  • or C-b backwards character
  • or C-f forwards character

bash Shortcuts

  • !! repeat last command
  • TAB or C-i complete word
  • TABTAB list possible completions