Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Linux Command Line Cheat Sheet (v0.

3)

­n specify number of lines to show


File Management Finding Files
xxd make a hexdump
cd change directory find search for files
cp copy files and directories File Editing find <path> ­name <filename>
­r recursive grep find files containing text pattern
­p preserve attibutes nano simple text editor grep <pattern> files
ln make links between files ­c show cursor position locate search for files in Locate database
­s symbolic link ­w disable line wrapping updatedb update Locate database
ls list directory contents vi text editor
i switch to insert mode
­l more info
esc switch to command mode File Manipulation
­a all files
­h human readable :w save file comm compare sorted files line by line
mkdir make directories :q quit cmp compare files byte by byte
mv move (rename) files cut select columns from files
pwd show current/working directory File Properties ­f column number
rm remove files or directories ­d specify column delimiter
chattr change file attributes
­r recursive diff compare files line by line
chgrp change group ownership
­f force fold wrap lines to specified width
­R recursive
rmdir remove empty directories grep filter lines matching a pattern
chmod change file access permissions
md5sum generate / check MD5 checksums
­R recursive
File Viewing chown change file owner and group
nl number lines
­R recursive
sort sort lines
cat show file content
du estimate file size strings show printable characters
head output the first part of files
­s summarize tee write to standard output and file
­n specify number of lines to show
­h human readable ­a append
less show scrollable output
file determine file type tr translate or delete characters
more show output in pages
lsattr list file attributes uniq remove duplicate successive lines
od dump file in octal format
stat display file or filesystem status wc count lines, words, and bytes
tail output the last part of files ­l count just lines
­f keep showing new added lines touch change file timestamps

KHLeuven – Departement Rega 1/4 Linux Command Line Cheat Sheet (v0.3)
File Packaging and Compressing System Information Process Management
bzip2 compress files date print or set system date and time at queue jobs for later execution
bunzip2 uncompress bzipped files free show memory information bg resume process in the background
gzip (un)compress files hostname show or set the system's name ctrl­c interrupt (stop) running process
gunzip uncompress gzipped files last show log of last logged in users ctrl­z suspend running process
tar pack or unpack files in tar archive lsof list open files fg bring process to foreground
­x extract from archive lspci list all PCI devices kill terminate a process
­t list contents of archive lsusb list all USB devices nice change process priority
­c create archive ps show current processes ps show current processes
­f specify archive filename ­e/­A all processes ­e/­A show all processes
­z perform gzip compression display a tree of processes
pstree renice change priority of running process
­j perform bzip2 compression
time summarize resource usage sleep delay a process
unzip unpack and uncompress zip files
top display real-time list of processes sudo run command as different user
zip package and compress files q quit top display real-time list of processes
­r recursive
uname print system information q quit
­a all information w show users and what they run
File System Management uptime show uptime and system load
report filesystem disk space usage w show users and what they run
df Getting Help
­h human readable which locate a command on the PATH
fsck check and repair a file system who show who is logged in apropos search manual pages
lsof list open files info read detailed documentation
­c select matching processes man view manual pages
­i show open network files whatis view command descriptions
mkfs create a file system (i.e. format)
mount mount a file system
mount <device> <mount point>
stat display file or filesystem status
­f show file system status
sync flush file system buffers
umount unmount a file system

KHLeuven – Departement Rega 2/4 Linux Command Line Cheat Sheet (v0.3)
& execute command in background
Networking I/O Redirection
<command> &
dig perform DNS lookup | pipe output of cmd 1 to cmd 2 alias create an alias for a command
dig @<server> <name> <type> <command1> | <command2> alias ls='ls ­­color=auto'
host perform DNS lookup < take input from file unalias remove a command alias
­t query type <command> < <file> ctrl­R search in command history
ifconfig configure a network interface > redirect output to file history list executed commands
netmask specify subnet mask <command> > <file>
up/down enable or disable interface >> append output to file
<command> >> <file>
netcat read/write over a network
2> redirect error stream to file Special keys
­l listening mode
<command> 2> <file> ctrl + D End-Of-File (ends standard input)
netstat print network connections
&> redirect output and error stream ctrl + U erase complete line
­l show listening sockets <command> &> <file>
­p show PID and program name ctrl + W erase last typed word
2>&1 redirect error stream to output
­t show TCP
<command> &> <file>
­u show UDP Misc
nmap network exploration scanner
ping send ICMP echo requests
Shell Wildcards cal display a calendar
clear clear terminal
route print / manipulate IP routing table * wildcard for zero or more chars
lpq show printer queue
scp secure copy (remote file copy) ? wildcard for zero or one char
scp <user1>@<host1>:file1 \  lpr print files
[abc] exactly one of the listed chars
  <user2>@<host2>:<file2> lprm cancel print job
[a­z] exactly one char from the range
­r recursive mail send and receive mail
[!abc] any char that is not listed specify mail subject
ssh SSH client (remote login) ­s
ssh <user>@<host> [!a­z] any char not in the range reset re-initialize terminal
tcpdump dump network traffic {go,no} exactly one of the words watch periodically execute program
­i specify network interface xargs build complex command lines
telnet communicate over TCP Shortcuts
telnet <host> <port>
<up> scroll through command history Fun and Games
traceroute print network route
<down> " " " " banner show large banner
wget non-interactive downloader
wget <url> <tab> file or command completion fortune print random adage
whois query whois database ~ home directory
cd ­ cd to last visited directory
\ command continues on next line

KHLeuven – Departement Rega 3/4 Linux Command Line Cheat Sheet (v0.3)
apt­get install <package>
System Administration apt­get remove <package>
passwd change user password rpm RedHat package management
rpm ­i <package>
su change user ID or become root
rpm ­e <package>
useradd create new user
shutdown bring the system down
­r reboot Scripting
perl execute Perl program
Regular Expressions ­e execute perl oneliner
­n execute for each line in given text file
. any single character ­p like -n, but prints resulting lines
[ ] one given characters
[aeiou] matches one vowel
[a­m] matches one of a,b,c,...,m
[^ ] any single char except given
[^0­9] matches one non-numeric char
^ start of the line
$ end of the line
* 0 or more times
+ 1 or more times
? 0 or 1 times
{x,y} at least x and max y times
( ) groups multiple expressions
([][][])+
| or
(me|you) matches 'me' or 'you'
( ) marks an expression
\n matches n-th marked expression This work is licensed under the Creative
([ao])x\1 matches 'axa' and 'oxo', not Commons Attribution-
'axo' NonCommercial-ShareAlike 2.5
License. To view a copy of this license, visit
http://creativecommons.org/licenses/by-nc-sa/2.5/ or
Package Management send a letter to Creative Commons, 543 Howard
Street, 5th Floor, San Francisco, California, 94105,
apt­get Debian package management USA.

KHLeuven – Departement Rega 4/4 Linux Command Line Cheat Sheet (v0.3)

You might also like