Linux Cheat Sheet

In this tutorial, we will list various practical Linux commands to be used only as a reference guide and by experienced Linux users. Not all Linux commands will be available on your system by default so consider installing the relevant package before use.

This Practical Guide to Linux Commands may list Linux commands you already know but cannot remember usage syntax as well as it may introduce some new Linux commands to improve your Linux command line efficiency. Note, this guide will not teach you how to use Linux commands since it relies on your experience to alter Linux commands syntax below to fit your needs.

In this tutorial you will learn:

  • Linux Cheat Sheet
Linux Cheat Sheet
Linux Cheat Sheet
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Backup and compression

Command Description
tar -c scripts/ | bzip2 -9 > scripts.tar.bz2 This linux command will use tar and bzip2 to compress scripts directory with a maximum compression
dd if=/dev/sda1 | gzip -c9 > /media/usb/sda1.dd.gz Backup and compress partition /dev/sda1 to a local file sda1.dd.gz
cat /media/usb/sda1.dd.gz | gzip -d | dd of=/dev/sdX1 Restore a compressed /dev/sda1 partition backup from a file to a /dev/sdX1 partition
dd bs=1M if=/dev/sda | gzip -c9 | ssh 'dd of=sda.dd.gz' Make a compressed backup of a hard drive /dev/sda and create a remote copy using ssh
find /etc/ -name '*.conf' | tar -c --files-from=- | bzip2 -9 > system_confs.tar.bz2 Find and compress all configuration files ( *.conf ) located in /etc/ directory into a file called system_confs.tar.bz2
dd if=/dev/sdb of=my.mbr bs=466 count=1 Backup and store a Master Boot Record of hard drive /dev/sdb into a file my.mbr
dd if=my.mbr of=/dev/sdX bs=466 count=1 Restore a Master Boot Record from my.mbr file to hard drive /dev/sdX
wget --mirror Create a complete mirror of a remote website with wget command
tar cvjf etc_$(date +%Y%m%d).tar.bz2 /etc/ Create an archive of /etc/ directory using tar command and compress it with bzip2. Compressed file will contain a current date within a filename.
tar xvjf etc.tar.bz2 Uncompress a bzip2 archive etc.tar.bz2
find /var/www/ -name '*.gif' | xargs cp -va --target-directory=/tmp/gifs Find all GIF files ( *.gif ) in /var/www/ and copy them to /tmp/gifs directory.
ssh '( mysqldump --password='pass' data > data.sql )' Remotely create a mysql database backup of data database into remote file data.sql
split -b 1000m linux-commands.iso Split a file linux-commands.iso into 1GB files. This will produce xaa, xab, xac.. files each of max size 1GB. Can be handy when working with FAT32 filesystem. See below on how to restore split file.
cat xa* > linux-commands.iso Restore a split file back into linux-commands.iso. See above on how to split file.

Searching the filesystem

Command Description
find /opt -name 'pass*' -or -size +1000k Find all files within /opt directory where file name start with pass or file size is 1000k or more. Feel free to use other boolean operators like AND and NOT.
locate -r '[^/]*\.conf' Search index and locate all files with *.conf extension. You may need to run updatedb first.
find /home/lilo/ -type f ! -perm 755 Search for all files in /home/lilo which do not have permissions 755
find /home/lilo/ -type f -perm 777 Search for all files in /home/lilo with a permissions 777
ls -ltr List all files in a current directory sorted by access/creation time
find /tmp/ -mmin -20 Find all files within /tmp created within last 20 minutes
find /tmp -iname file -exec chmod 777 {} \; search for a file named file ( case insensitive ) and change its permissions to 777
find /var/log/ -size 8k Search for files int /var/log with size of 8k
find / * -perm +6000 -type f -exec ls -ld {} \; > setuid.txt Create a list setuid.txt containing names of all binary files with setuid and setguid


Command Description
curlftpfs /mnt/my_ftp/ Mount remote ftp server to a local filesystem /mnt/my_ftp/
ssh '( cd /tmp/ && touch ssh_file.txt )' Execute commands remotely using ssh.
ssh '( cat /etc/passwd )' > /tmp/passwd create a local copy of remote /etc/passwd
airodump-ng -c 6 -w data-capture wlan0 sniffing wireless network packets using wlan0 wireless interface
macchanger -r eth0 Create a fake MAC address for an eth0 network interface
ssh -L 4500: Create a ssh tunnel for telnet using local port 4500
ssh -L Tunnel traffic from a local system port 8025 to port on port 25
lsof -i tcp:22 Displays a service which uses port 22
ethtool eth0 Show status of eth0 network interface
iwlist wlan0 scanning Scan for available wireless networks using wlan0 interface
netstat -ant List all TCP ports on the system
netstat -tupl List all available services on the system
ip route add default via Set a default route via

Arithmetics and conversions

Command Description
echo $((0xFFF)) Convert hexadecimal number ( in this case FFF ) to decimal using shell expansion.
echo $((8#44)) Convert octal number ( in this case 44 ) to decimal using shell expansion.
echo "obase=16; ibase=10; 555;" | bc Convert decimal number ( in this case 555 ) to hexadecimal using shell expansion.
echo "obase=8; ibase=10; 64;" | bc Convert decimal number ( in this case 64 ) to octal using shell expansion.
echo "obase=16; ibase=8; 255;" | bc Convert octal number ( in this case 255 ) to hexadecimal using shell expansion.
echo "3447.2 * 343.61" | bc Multiply a number. For addition and subtraction use “+” and “-” instead of “*”
echo "scale=10; 100 / 3" | bc Divide number with a floating point precision 10
units -t '13miles' 'km' Convert miles to kilometers ( eg. 13 miles )
units -t '10.5inches' 'cm' Convert inches to centimeters ( eg. 10.5 inches )
units -t '78344352ms' 'hour' Convert milliseconds to hours

Text manipulation

Command Description
dd if=commands.txt conv=lcase Convert all characters from Uppercase to Lowercase This will not alter a source file, but create new file called
rename 's/\.sh$/.bash/' *.sh Rename all files in a current working directory with extension *.sh to *.bash
rename 's/^/new_/' *.conf Add a prefix new_ to all files in a current working directory with extension *.conf
grep -v ^\# /etc/ntp.conf | grep . Show only uncommented lines within a configuration file as well as ingnore empty lines.
ls | grep " " | while read -r f; do mv "$f" `echo $f | tr ' ' '_'`; done Remove space from all filenames in a current working directory
ls | while read -r f; do mv "$f" `echo $f | tr '[A-Z]' '[a-z]'`; done Change all filenames in a current directory from uppercase to lowercase.

Date and Time

Command Description
date -ud@1244763573 Convert an epoch time to Coordinated Universal Time
date -d "Dec 23 18:10:02 EST 2010" +%s Convert date to an epoch time
echo 'wget -c' | at 03:00 Download an iso image at 3AM. -c allows you to continue download in case of lost network connection.
date -d '2 Feb 2013' +%A What day would be/was 2 Feb 2013? …Saturday
units -t '10 days + 6 hours + 26 minutes + 59 seconds' 'seconds' Convert time to seconds


Command Description
wodim --devices Get a burner block device filename
cdrecord -v blank=all dev=/dev/scd0 Erase / full blank your cd-rw. Note: use wodim –devices to get your block device file name.
cdrecord -v blank=fast dev=/dev/scd0 Erase fast your cd-rw. Note: use wodim –devices to get your block device file name.
fmpeg -i out.wav -acodec libmp3lame out.mp3 Convert WAV audio format to MP3
normalize-mp3 *.mp3 Normalize a volume for all your MP3 audio files to reduce sudden volume spikes between tracks.
cat file1.mp3 file2.mp3 > out.mp3 Join all MP3 audio files into a single track.
sox file1.wav file2.wav file3.wav out.wav Join all wav audio files into a single track.
for i in $( ls ); do ffmpeg -i $i $i.wav; done Convert all MP3 or AC3 audio files into WAV format.
normalize-audio -m *.wav Normalize a volume for all your WAV audio files to reduce sudden volume spikes between tracks.
cdrecord -v -nofix -eject dev='/dev/scd0' -audio -pad *.wav Burn all WAV audio files on a CD using device /dev/scd0
cdrecord -v -fix -eject dev='/dev/scd0' Close a CD session using /dev/scd0 burning device.
ffmpeg -f x11grab -s xga -r 25 -i :0 -sameq screen.mpg Record a video of your screen into a screen.mpg video file.
for i in $( ls *.jpg ); do convert -resize 25% $i new_$i; done Resize all images in your current directory ( in this case images with extension *jpg ) to a 25% of the original size.
mkisofs -o /tmp/cd.iso /path/to/your/files/ Create an ISO image from files in /path/to/your/files/
wodim -eject -tao speed=0 dev=/dev/scd0 -v -data /my/image.iso Burn an ISO image using wodim and /dev/scd0 burning device.
mount -t iso9660 /path/to/iso/file.iso /mnt/iso -o loop Mount ISO image to a /mnt/iso directory.
xrandr --output VGA --auto Clone a video output to yout VGA port. Useful for presentations. Use xrandr with no arguments to see whether VGA is connected to a projector.
arecord -d 10 /tmp/out.wav Test your microphone.

Disk Usage and Administration

Command Description
time dd if=/dev/hdb of=/dev/null bs=1024k Non-destructive hard drive speed and size test. Replace /dev/hdb with your hard drive.
du -m --max-depth 1 | sort -rn | head -11 Get a directory size of all directories in a current working directory, sort them and show first 10 largest. Note: the first directory is a parent directory.
du -s * | sort -k1,1rn | head Display top 10 largest files or directories in a current working directory.
dd if=/dev/zero of=/sp bs=10000 count=10000; mkswap /sp; swapon /sp Create a file /sp with size of 100MB, generate swap signature and include /sp file into overall system’s swap memory. This will add another 100MB to your system’s swap.
dpkg-query -Wf='${Installed-Size;10}\t${Package}\n' | sort -k1,1rn DEB package management only. Show all installed packages and sort them from largest to smallest.
rpm -q -a --qf '%10{SIZE}\t%{NAME}\n' | sort -k1,1rn RPM package management only. Show all installed packages and sort them from largest to smallest.
head -c 100000000 /dev/urandom > Create a with a random data and approximately with 100MB in size.
dd bs=1 seek=2TB if=/dev/null of=~/large-file Create a 2TB ~/large-file taking no space.
df -h . Information about free space for a partition located under your current working directory.

Hardware information

Command Description
biosdecode Retrieve BIOS information.
dmidecode -s bios-vendor Retrieve your BIOS vendor
dmidecode --type baseboard Retrieve information about your motherboard
ls -la /dev/disk/by-id/usb-* USB disk device files. NOTE: USB disk must be plug-in. May not work on all systems.
hdparm -I /dev/sdx Hard drive model of /dev/sdx.
hdparm -tT /dev/sdx Hard drive speed. NOTE: this test disregards a filesystem.
hddtemp /dev/sda Check temperature of /dev/sda hard drive
lspci | grep VGA Get information about your graphic card
dmidecode --type 4 Retrieve your processor information. Also try cat /proc/cpuinfo
x86info -a 2> /dev/null | grep Connector | uniq Retrieve a processor socket type. For this to work you need to have a x86info command available. Try install x86info package.
dmidecode -t 17 Detect number of RAM slots used, their speed and size. Also try: lshw -C memory -short
cat /dev/sndstat Check your sound card settings and module in use.
powersave -b Get a battery information.
free -m Check system’s free memory. This includes swap memory. Alternatives are: top, cat /proc/meminfo
fdisk -l | grep GB Check a size of all hard drives including USB.

Tips & Tricks

Command Description
head -c 4 /dev/urandom | mimencode Generate 8 random characters. NOTE: mimencode is part of metamail package
echo "DISPLAY=$DISPLAY xmessage -center 'abc'" | at "NOW +1hour" Display a GUI message in the center of your screen in hour from now.
:(){ :|:& };: Fork Bomb. Simple way to crash your system.
ccrypt mypasswords.txt Encrypt a file.
ccdecrypt mypasswords.txt.cpt Decrypt a previous encrypted file with ccrypt.

Closing Thoughts

Feel free to reference this cheat sheet any time that you need a quick refresher. The goal here is to save you as much time as possible when trying to remember a certain command.

Two more commands that every user should know are the man command and apropos command. Knowing these two commands, which are very simple to use, will allow you to look up all the options that go with certain commands. apropos also works well as a manual search utility so you don’t need to leave your terminal very often.