Linux command line cheat sheet

category command description
system information date outputs the current date/time
cal outputs an ASCII calendar
uname print information about the system
-a system information
-r kernel release
time measure how long a program takes to run
lsb_release -a show which version of ubuntu installed
uptime show how long the system has been running + load
hostname show system host name
-I display the IP address of the host
last reboot show system reboot history
w display who is online
whoami who you are logged in as
man command show manual for command
hardware information cat /proc/cpuinfo display CPU information
cat /proc/meminfo display memory information
free -h display free and used memory ( -hfor human readable,-mfor MB, -gfor GB.)
lspci -tv display PCI devices
lsusb -tv display USB devices
dmidecode display DMI/SMBIOS (hardware info) from theBIOS
hdparm get/set hard disk parameters
performance monitoring and statistics top display and manage the top processes
mpstat display processor related statistics
vmstat display virtual memory statistics
iostat display I/O statistics
lsusb -tv display USB devices
tcpdump -i eth0 capture and display all packets on interface eth0
tcpdump -i eth0 'port 80' monitor all traffic on port 80 (HTTP)
lsof list all open files on the system
-u user list files opened by user
watch df -h execute "df -h", showing periodic updates
user information and management id display the user and group ids of your current user
last display the last users who have logged onto the system
who show who is logged into the system
w show who is logged in and what they are doing
groupadd test create a group named "test"
useradd -c "John Smith" -m john create an account named john, with a comment of "John Smith" and create the user's home directory
userdel john delete the john account
usermod -aG sales john Add the john account to the sales group
basic shell clear clear all previous commands' output text from the terminal
exit (or logout) quits the shell
alias, unalias give a pseudonym to another command
(you may need to enclose the command in quotes if it contains spaces or operators)
history show a list of all past commands you have typed into this shell
directories ls list files in a directory
-al , list files in a long detailed format
pwd displays the shell's present working directory
mkdir directory creates a new directory with the given name
rm -r directory remove the directory and its contents recursively
-rf directory , forcefully remove directory recursively
rmdir removes the directory with the given name (the directory must be empty)
cp -r source_directory destination Copy source_directory recursively to destination. If destination exists, copy source_directory into destination,
otherwise create destination with the contents of source_directory
directory navigation cd /dir changes the shell's working directory to the given directory; can be a relative or absolute path
cd .. to go up one level of the directory tree. (Change into the parent directory.)
cd go to the $HOME directory
file operations cp file1 file2 copy file1 to file2
mv file1 file2 rename or move file1 to file2. If file2 is an existing directory, move file1 into directory file2
rm file deletes a file
-f file , Force removal of file without prompting for confirmation
touch file update the last-modified time of a file (or create an empty file)
ln -s /path/to/file linkname create symbolic link to linkname
diff output differences between two files
file determine file type
cmp compare the contents of two files
paste merge file data
cut cut out selected fields of each line of a file
split split file into smaller files
join join files on some common field
tr translate characters
look find lines in sorted data
mount show mounted file systems
file examination and disk usage cat output the contents of a file
more (or less) output the contents of a file, one page at a time
head, tail output the beginning or ending of a file
wc output a count of the number of characters, lines, words, etc. in a file
du report disk space used by a file/directory
-ah , display disk usage for all files and directories in human readable format
-sh , display total disk usage off the current directory
df -h show free and used space on mounted filesystems
df -i show free and used inodes on mounted filesystems
fdisk -l display disks partitions sizes and types
file permissions U = User G = Group W = World
r = read, w = write, x = execute,
– = no access
 U   G   W
rwxrwxrwx  chmod 777 filename
rwxrwxr—x  chmod 775 filename
chmod change the permissions on a file or group of files
chown change the owner of a file
chgrp change the group associated with a file
umask change the default permissions given to newly created files
searching and sorting grep pattern file search for pattern (string or expression) in file
-r pattern directory , search recursively for pattern in directory
sort convert an input into a sorted output
uniq report repeated lines in a file
find search for files by name within a given directory
/home/john -name 'prefix*' , find files in /home/john that start with "prefix"
/home -size +100M , find files larger than 100MB in /home
xargs launch a command over each of a set of lines of input (often used with find)
locate search for files and directories by name on the entire system
which shows the complete path of a command or file
archives (tar files)
compression
tar Unix archiving/de-archiving program
cf archive.tar directory , create tar named archive .tar containing directory
cjf archive.tar.bz2 directory , create a tar file with bzip2 compression
xf archive.tar , extract the contents from archive.tar. tar czf
xzf archive.tar , extract a gzip compressed tar file
xjf archive.tar.bz2 , extract a bzip2 compressed tar file
archive.tar.gz directory create a gzip compressed tar file name archive.tar.gz
zip, unzip create a .zip archive or extract its contents
gzip, gunzip GNU compression/decompression files
bzip2, bunzip2 improved compression/decompression files
uncompress uncompress files
process management ps list the processes you are running; every process has a unique integer id number (PID)
-ef , display all the currently running processes on the system
top see what processes are using the most CPU/memory, and show system memory/CPU stats
kill pid terminate a process with process ID of pid
killall terminate a group of processes by name
^C or ^\ (hotkey) terminates (kills) the currently running process
^Z (hotkey) suspends the currently running process
& when & is placed at the end of a command, that command is run in the background
bg display stopped or background jobs
fg brings the most recent background job to foreground
users and groups whoami outputs your user name
passwd changes your password
groups list the groups to which a user belongs
sudo execute a single command as the super-user
su log in to a shell as the super-user
multi-user environments hostname outputs the name of the current computer/server
w, finger see who is logged in to this computer
write sends a message to another user logged in to this computer
wall broadcasts a message to all other users logged in to this computer
.plan (filename) a special hidden file you can create in your home directory, whose contents will be displayed when other users run finger on you. Was originally intended to be used to tell others what you are up to right now. (the Twitter of the 1970s!)
networking ifconfig -a display all network interfaces and ip address
ping host send ICMP echo request to host
ssh, sftp, scp connect to a remote Unix server; open a shell on it or send/receive files from it
wget http://domain.com/file download from a URL (http://domain.com/file) and save it to a file on the local hard drive
curl download from a URL and output its contents to the console
whois domain display DNS information for domain
dig domain display whois information for domain
-x IP_ADDRESS , reverse lookup of IP_ADDRESS
host domain display DNS ip address for domain
hostname -i display the network address of the host name
-I , display all local ip addresses
netstat -nutlp Display listening tcp and udp ports and corresponding programs
ftp file transfer program
tftp trivial file transfer program
sftp secure shell file transfer program
rcp remote file copy
telnet make terminal connection to another host
rlogin remote login to a Linux host
rsh remote shell
pine, mail text-only email programs
text editors pico, nano crappy but simple text editors (recommended)
emacs a complicated text editor (not recommended)
vi, vim another complicated text editor (not recommended)
gedit standard text editor
regular expressions sed stream editor; find/replace based on regular expressions
egrep extended version of grep that matches regular expressions
awk pattern scanning and processing language
programming make maintain groups of programs
bc an arbitrary precision calculator language
javac, java compile or run a Java program
gcc GNU ANSI C Compiler
ctrace C program debugger
indent indent and format C program source
cxref generate C program cross reference
g++ GNU C++ Compiler
bcpp make C++ beautifier
size print program's sizes
nm print program's name list
strip remove symbol table and relocation bits
python, perl, ruby, ... compile or run programs in various other languages
build management make determine which parts of a system must be recompiled, and compile them
svn, cvs Subversion and CVS version-control systems
miscellaneous yes output "y" (or another string) over and over
sleep, usleep pause for a given number of seconds or ms
xeyes googley eyes that follow your mouse cursor
shell scripting echo, printf like println for the shell; outputs a message or value
read reads a value from standard input
set, unset give values to a variable, or delete a variable
export sets a variable that any sub-programs launched by this shell can see
let for computing integer variable values
source executes commands/statements stored in another file
(useful for re-loading .bash_profile without logging out)
if, [, for, while bash control statements
seq outputs a sequence of integers (used with for loops)

Keyboard shortcuts and special characters:
(^X means hold Ctrl key and press X)

key / character description
Up arrow repeat previous command(s)
Home/End or ^A/^E move cursor to start/end of line
* "wildcard", matches any file(s)
Tab auto-completes a partially typed file/directory/command name
^C or ^\ kills the currently running process
^D end-of-input; press this if a program is reading input from your keyboard and you want to notify it that you are finished
^Z suspends (pauses) the currently running process; use fg or bg to resume it
^S never ever press this; worst hotkey ever; totally locks up your shell until you press ^Q