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
Software Requirements and Linux Command Line Conventions
Category
Requirements, Conventions or Software Version Used
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
Find all GIF files ( *.gif ) in /var/www/ and copy them to /tmp/gifs directory.
ssh user@linuxconfig.org '( 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
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.
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.
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 > file.data
Create a file.data 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.