Show Menu
Cheatography

Linux Command Line Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

System Commands

uname -a
Show system and kernel
head -n1 /etc/issue
Show distri­­bution
whoami
Show your username
man command
Show manual for command
date
Show system date
date --utc
Show system date in UTC

Magic Keys

CTRL-A­LT-BKSP
Restart X display if frozen
ALT-SysRq+R+S+E­+I+U+B
Restart Ubuntu safely when it is frozen
ALT-SysRq+R+S+E­+I+U+O
Safely shutting down Ubuntu when it is frozen
The minus in between keys indicates they should be held down together. The plus indicates that the keys should be pressed in sequence. If keys are in bold then they should be held down during the entire sequence. More inform­ation.

Other useful commands

watch -n 5 'ntpq -p'
Issue the 'ntpq -p' command every 5 seconds and display output

Package Management

apt-get update
Refresh available updates.
apt-get upgrade
Upgrade all packages.
apt-get install pkg
Install pkg.
apt-get purge pkg
Uninstall pkg.
apt-get autoremove
Remove obsolete packages.
apt-get -f install
Try to fix broken packages.
dpkg -i pkg.deb
Install pkg from a deb file.
apt-get build-dep pkg
Install depend­encies for pkg so that it can be built from source.
apt-get -y cmd
Automatic yes response to prompts.
These commands should be run with sudo.
 

File Operations

touch file1
Create file1
cat file1 file2
Concat­­enate files and output
less file1
View and paginate file1
ln -s /path/­to/src /path/­to/dst
Create symbolic link at dst to src
cp file1 file2
Copy file1 to file2
mv file1 file2
Move file1 to file2
rm file1
Delete file1
head file1
Show first 10 lines of file1
tail file1
Show last 10 lines of file1
tail -f file1
Output last lines of file1 as it changes
wc file1
Display the number of lines in file1
file file1
Get type of file1

File Compre­ssion

tar -czvf file1.tgz file1
Tar and gzip file1
tar -xvzf file1.tgz
Decompress a file that was tared and gzipped
Remove the z flag if the file is tarred without being gzipped

References

 

Directory Operations

pwd
Show current directory
mkdir dir
Make directory dir
cd dir
Change directory to dir
cd ..
Go up a directory
cd -
Go to previous directory
ls
List files
rm -r dir
Delete dir recursivly

ls Options

-a
Show all (including hidden)
-l
Long listing format
-R
Recursive list
-t
Sort by last modified
-S
Sort by file size
-h
Human readable file sizes (use with -l)

Bash Shortcuts

CTRL-c
Stop current command
CTRL-a
Go to start of line
CTRL-e
Go to end of line
CTRL-r
Search history
CTRL-z
Sleep program
bg
Send running process into the background
fg
Foreground a backgr­ounded process
!!
Repeat last command
!abc
Run last command starting with abc
^abc^123
Run previous command, replacing abc with 123

SSH Options

-D1080
Dynamic port forwarding via SOCKS on port 1080
-o UserKn­own­Hos­tsF­ile­=/d­ev/null
Use an empty known hosts file
-o Strict­Hos­tKe­yCh­eck­ing=no
No strict host key checking
-X
Enable X11for­warding