Operations 46 min read
The Most Comprehensive Linux Command Cheat Sheet
This article provides an exhaustive reference of Linux command‑line utilities, covering basic system information, file and directory management, searching, mounting, disk usage, user and group administration, permissions, special attributes, archiving, compression, backup, networking, VIM editing, and RPM package management, complete with concrete examples and command syntax for each task.
Linux Tech Enthusiast
Linux Tech Enthusiast
1. Basic Commands
uname -m # display processor architecture
uname -r # display kernel version
dmidecode -q # display hardware components
hdparm -i /dev/hda # list disk architecture features
hdparm -tT /dev/sda# perform test read on disk
arch # display processor architecture
cat /proc/cpuinfo # show CPU info
cat /proc/interrupts# show interrupts
cat /proc/meminfo # check memory usage
cat /proc/swaps # show active swap devices
cat /proc/version # display kernel version
cat /proc/net/dev # list network adapters and stats
cat /proc/mounts # show mounted filesystems
lspci -tv # list PCI devices
lsusb -tv # list USB devices
date # show system date
cal 2007 # display calendar for 2007
date 041217002007.00# set date and time (MMDDhhmmYY.ss)
clock -w # write BIOS clock2. Shutdown and Reboot
shutdown -h now # immediate shutdown
init 0 # shutdown (method 2)
telinit 0 # shutdown (method 3)
shutdown -h HH:MM # schedule shutdown at specific time
shutdown -c # cancel scheduled shutdown
shutdown -r now # immediate reboot
reboot # immediate reboot
logout # log out current session3. Files and Directories
cd /home # change to /home directory
cd .. # go up one level
cd ../.. # go up two levels
cd # go to home directory
cd ~user1 # go to user1's home directory
cd - # return to previous directory
pwd # print working directory
ls # list files
ls -F # list files with type indicators
ls -l # detailed list
ls -a # include hidden files
ls *[0-9]* # list files containing numbers
tree # display directory tree (method 1)
lstree # display directory tree (method 2)
mkdir dir1 # create directory dir1
mkdir dir1 dir2 # create two directories
mkdir -p /tmp/dir1/dir2# create nested directories
rm -f file1 # force delete file1
rmdir dir1 # remove empty directory dir1
rm -rf dir1 # recursively delete dir1 and its contents
rm -rf dir1 dir2 # delete two directories recursively
mv dir1 new_dir # rename/move directory
cp file1 file2 # copy file1 to file2
cp -a /tmp/dir1 . # copy all files from dir1 to current directory
cp -a dir1 dir2 # copy directory
ln -s file1 lnk1 # create symbolic link
ln file1 lnk1 # create hard link
touch -t 0712250000 file1# set timestamp (YYMMDDhhmm)
file file1 # display MIME type of file
iconv -l # list known encodings
iconv -f from -t to inputFile > outputFile # convert encoding
find . -maxdepth 1 -name *.jpg -print -exec convert "{}" -resize 80x60 "thumbs/{}" \; # batch resize images4. File Search
find / -name file1 # search from root for file1
find / -user user1 # find files owned by user1
find /home/user1 -name \*.bin # find .bin files in /home/user1
find /usr/bin -type f -atime +100 # files not accessed in 100 days
find /usr/bin -type f -mtime -10 # files modified in last 10 days
find / -name \*.rpm -exec chmod 755 "{}" \; # set permissions on .rpm files
find / -xdev -name \*.rpm # find .rpm files ignoring removable media
locate \*.ps # locate .ps files (run updatedb first)
whereis halt # locate binary, source, man page for halt
which halt # show full path of halt executable5. Mount a Filesystem
mount /dev/hda2 /mnt/hda2 # mount partition hda2
umount /dev/hda2 # unmount partition
fuser -km /mnt/hda2 # force unmount if busy
umount -n /mnt/hda2 # unmount without writing /etc/mtab
mount /dev/fd0 /mnt/floppy # mount floppy
mount /dev/cdrom /mnt/cdrom # mount CD/DVD
mount /dev/hdc /mnt/cdrecorder # mount CDRW/DVD
mount /dev/hdb /mnt/cdrecorder # mount another CDRW/DVD
mount -o loop file.iso /mnt/cdrom # mount ISO image
mount -t vfat /dev/hda5 /mnt/hda5 # mount FAT32 filesystem
mount /dev/sda1 /mnt/usbdisk # mount USB flash drive
mount -t smbfs -o username=user,password=pass //WinClient/share /mnt/share # mount Windows share6. Disk Space
df -h # show mounted partitions with human‑readable sizes
ls -lSr | more # list files sorted by size
du -sh dir1 # estimate disk usage of dir1
du -sk * | sort -rn # sort directories/files by size
rpm -q -a --qf '%10{SIZE}t%{NAME}n' | sort -k1,1n # list installed RPMs by size (Fedora/RedHat)
dpkg-query -W -f='${Installed-Size;10}\t${Package}
' | sort -k1,1n # list installed DEBs by size (Debian/Ubuntu)7. Users and Groups
groupadd group_name # create new group
groupdel group_name # delete group
groupmod -n new_group_name old_group_name # rename group
useradd -c "Name Surname" -g admin -d /home/user1 -s /bin/bash user1 # create user in group admin
useradd user1 # create user
userdel -r user1 # delete user and home directory
usermod -c "User FTP" -g system -d /ftp/user1 -s /bin/nologin user1 # modify user attributes
passwd # change password
passwd user1 # change password for user1 (root only)
chage -E 2005-12-31 user1 # set password expiration date
pwck # check /etc/passwd syntax
grpck # check /etc/group syntax
newgrp group_name # switch to new primary group8. File Permissions
chmod ugo+rwx directory1 # give read/write/execute to user, group, others
chmod go-rwx directory1 # remove read/write/execute from group and others
chown user1 file1 # change file owner
chown -R user1 directory1 # change owner recursively
chgrp group1 file1 # change group ownership
chown user1:group1 file1 # change both owner and group
chmod u+s /bin/file1 # set SUID bit
chmod u-s /bin/file1 # remove SUID bit
chmod g+s /home/public # set SGID on directory
chmod g-s /home/public # remove SGID
chmod o+t /home/public # set sticky bit
chmod o-t /home/public # remove sticky bit
chmod +x file_path # add execute permission for all
chmod -x file_path # remove execute permission for all
chmod u+x file_path # add execute for owner
chmod g+x file_path # add execute for group
chmod o+x file_path # add execute for others
chmod ug+x file_path # add execute for owner and group
chmod =wx file_path # set write and execute, remove read
chmod ug=wx file_path # set write and execute for owner and group9. Special File Attributes
chattr +a file1 # allow only append writes
chattr +c file1 # enable automatic compression
chattr +d file1 # exclude from dump backups
chattr +i file1 # make immutable (cannot delete, modify, rename)
chattr +s file1 # allow secure deletion
chattr +S file1 # sync changes immediately after write
chattr +u file1 # allow recovery of a deleted file
lsattr # list special attributes10. Archiving and Compression
bunzip2 file1.bz2 # decompress .bz2 file
bzip2 file1 # compress file with bzip2
gunzip file1.gz # decompress .gz file
gzip file1 # compress file with gzip
gzip -9 file1 # maximum compression
rar a file1.rar test_file # create .rar archive
rar a file1.rar file1 file2 dir1# add multiple items to .rar
rar x file1.rar # extract .rar archive
unrar x file1.rar # extract .rar archive
tar -cvf archive.tar file1 # create uncompressed tarball
tar -cvf archive.tar file1 file2 dir1 # create tarball with multiple items
tar -tf archive.tar # list contents of tarball
tar -xvf archive.tar # extract tarball
tar -xvf archive.tar -C /tmp # extract to /tmp
tar -cvfj archive.tar.bz2 dir1 # create bzip2‑compressed tarball
tar -xvfj archive.tar.bz2 # extract bzip2 tarball
tar -cvfz archive.tar.gz dir1 # create gzip‑compressed tarball
tar -xvfz archive.tar.gz # extract gzip tarball
zip file1.zip file1 # create zip archive
zip -r file1.zip file1 file2 dir1 # recursively zip multiple items
unzip file1.zip # extract zip archive11. RPM Packages (Fedora/RedHat)
rpm -ivh package.rpm # install RPM
rpm -ivh --nodeps package.rpm # install ignoring dependencies
rpm -U package.rpm # upgrade without changing config files
rpm -F package.rpm # upgrade already‑installed package
rpm -e package_name.rpm # erase package
rpm -qa # list all installed RPMs
rpm -qa | grep httpd # filter installed RPMs by name
rpm -qi package_name # show detailed info of installed package
rpm -qg "System Environment/Daemons" # list RPMs in a group
rpm -ql package_name # list files provided by package
rpm -qc package_name # list config files of package
rpm -q --whatrequires package_name # show packages that depend on this one
rpm -q --whatprovides package_name # show what provides this capability
rpm -q --scripts package_name # show install/remove scripts
rpm -q --changelog package_name # show changelog
rpm -qf /etc/httpd/conf/httpd.conf # find which RPM provides a file
rpm -qp package.rpm -l # list files in an uninstalled RPM
rpm --import /media/cdrom/RPM-GPG-KEY # import GPG key
rpm --checksig package.rpm # verify package integrity
rpm -V package_name # verify size, permissions, MD5, timestamps
rpm -Va # verify all installed RPMs (use with care)
rpm -Vp package.rpm # verify an uninstalled package
rpm2cpio package.rpm | cpio --extract --make-directories *bin* # run executable from RPM
rpm -ivh /usr/src/redhat/RPMS/arch/package.rpm # install built RPM from source
rpmbuild --rebuild package_name.src.rpm # rebuild source RPM12. YUM Package Manager (Fedora/RedHat)
yum install package_name # download and install RPM
yum localinstall package_name.rpm # install RPM using local repo to resolve deps
yum update package_name.rpm # update all installed RPMs
yum update package_name # update a specific RPM
yum remove package_name # delete an RPM
yum list # list all installed packages
yum search package_name # search repository for package
yum clean packages # clean downloaded package cache
yum clean headers # clean header files
yum clean all # clean all caches13. DEB Packages (Debian/Ubuntu)
dpkg -i package.deb # install or upgrade DEB
dpkg -r package_name # remove DEB package
dpkg -l # list installed DEBs
dpkg -l | grep httpd # filter installed DEBs by name
dpkg -s package_name # show package information
dpkg -L package_name # list files provided by DEB
dpkg --contents package.deb # list contents of an uninstalled DEB
dpkg -S /bin/ping # find which DEB provides a file
apt-get install package_name # install or upgrade DEB
apt-cdrom install package_name # install from CD
apt-get update # refresh package list
apt-get upgrade # upgrade all installed packages
apt-get remove package_name # remove DEB package
apt-get check # verify repository integrity
apt-get clean # clean package cache
apt-cache search searched-package# search for packages containing a string14. Viewing File Contents
cat file1 # display file from start
tac file1 # display file in reverse order
more file1 # page through long file
less file1 # page forward and backward
head -2 file1 # first two lines
tail -2 file1 # last two lines
tail -f /var/log/messages # follow file as it grows15. Text Processing
cat file1 file2 | command > file1_in.txt_or_file1_out.txt # pipe files to command
cat file1 | command (sed|grep|awk) > result.txt # filter and write output
grep Aug /var/log/messages # search for "Aug"
grep ^Aug /var/log/messages # lines starting with "Aug"
grep [0-9] /var/log/messages # lines containing digits
grep Aug -R /var/log/* # recursive search for "Aug"
sed 's/stringa1/stringa2/g' example.txt # replace stringa1 with stringa2
sed '/^$/d' example.txt # delete empty lines
sed '/ *#/d; /^$/d' example.txt # delete comments and empty lines
echo "example" | tr '[:lower:]' '[:upper:]' # convert to upper case
sed -e '1d' result.txt # delete first line
sed -n '/stringa1/p' result.txt # print lines containing stringa1
sed -e 's/ *$//' result.txt # trim trailing spaces
sed -e 's/stringa1//g' result.txt # delete all occurrences of stringa1
sed -n '1,5p;5q' result.txt # print lines 1‑5 then quit
sed -n '5p;5q' result.txt # print line 5 then quit
sed -e 's/00*/0/g' result.txt # replace multiple zeros with single zero
cat -n file1 # number lines
cat file1 | awk 'NR%2==1' # delete even lines
echo a b c | awk '{print $1}' # print first column
echo a b c | awk '{print $1,$3}' # print first and third columns
paste file1 file2 # merge two files column‑wise
paste -d '+' file1 file2 # merge with '+' delimiter
sort file1 file2 # sort combined files
sort file1 file2 | uniq # unique lines (union)
sort file1 file2 | uniq -u # lines unique to each file (difference)
sort file1 file2 | uniq -d # common lines (intersection)
comm -1 file1 file2 # remove lines only in file1
comm -2 file1 file2 # remove lines only in file2
comm -3 file1 file2 # show only common lines16. Character Set and File Format Conversion
dos2unix filedos.txt fileunix.txt # convert DOS to UNIX line endings
unix2dos fileunix.txt filedos.txt # convert UNIX to DOS line endings
recode ..HTML < page.txt > page.html# convert text to HTML
recode -l | more # list all supported conversions17. Filesystem Analysis
badblocks -v /dev/hda1 # check for bad blocks
fsck /dev/hda1 # check and repair filesystem
fsck.ext2 /dev/hda1 # check ext2 filesystem
e2fsck /dev/hda1 # check ext2 filesystem
e2fsck -j /dev/hda1 # check ext3 (with journal)
fsck.ext3 /dev/hda1 # check ext3 filesystem
fsck.vfat /dev/hda1 # check FAT filesystem
fsck.msdos /dev/hda1 # check DOS filesystem
dosfsck /dev/hda1 # check DOS filesystem18. Initialize a Filesystem
mkfs /dev/hda1 # create filesystem on hda1
mke2fs /dev/hda1 # create ext2 filesystem
mke2fs -j /dev/hda1 # create ext3 (journaled) filesystem
mkfs -t vfat -F 32 /dev/hda1 # create FAT32 filesystem
fdformat -n /dev/fd0 # format floppy
mkswap /dev/hda3 # create swap area19. SWAP Filesystem
mkswap /dev/hda3 # create swap partition
swapon /dev/hda3 # enable swap
swapon /dev/hda2 /dev/hdb3 # enable two swap partitions20. Backup
dump -0aj -f /tmp/home0.bak /home # full backup of /home
dump -1aj -f /tmp/home0.bak /home # interactive backup of /home
restore -if /tmp/home0.bak # restore interactive backup
rsync -rogpav --delete /home /tmp # sync directories
rsync -rogpav -e ssh --delete /home ip_address:/tmp # rsync over SSH
rsync -az -e ssh --delete ip_addr:/home/public /home/local # remote to local sync with compression
rsync -az -e ssh --delete /home/local ip_addr:/home/public # local to remote sync
dd bs=1M if=/dev/hda | gzip | ssh user@ip_addr 'dd of=hda.gz' # backup disk over SSH
dd if=/dev/sda of=/tmp/file1 # backup disk to file
tar -Puf backup.tar /home/user # interactive backup of /home/user
(cd /tmp/local && tar c .) | ssh -C user@ip_addr 'cd /home/share && tar x -p' # copy directory via SSH
(tar c /home) | ssh -C user@ip_addr 'cd /home/backup && tar x -p' # copy local dir to remote
tar cf - . | (cd /tmp/backup ; tar xf -) # copy directory locally preserving permissions
find /home/user1 -name "*.txt" | xargs cp -av --target-directory=/home/backup/ --parents # copy all .txt files preserving hierarchy
find /var/log -name "*.log" | tar cv --files-from=- | bzip2 > log.tar.bz2 # archive log files
dd if=/dev/hda of=/dev/fd0 bs=512 count=1 # copy MBR to floppy
dd if=/dev/fd0 of=/dev/hda bs=512 count=1 # restore MBR from floppy21. Optical Media
cdrecord -v gracetime=2 dev=/dev/cdrom -eject blank=fast -force # erase rewritable CD
mkisofs /dev/cdrom > cd.iso # create ISO image from CD
mkisofs /dev/cdrom | gzip > cd_iso.gz # create compressed ISO image
mkisofs -J -allow-leading-dots -R -V "Label CD" -iso-level 4 -o ./cd.iso data_cd # create ISO from directory
cdrecord -v dev=/dev/cdrom cd.iso # burn ISO image
gzip -dc cd_iso.gz | cdrecord dev=/dev/cdrom # burn compressed ISO
mount -o loop cd.iso /mnt/iso # mount ISO image
cd-paranoia -B # rip audio tracks to WAV
cd-paranoia -- "-3" # rip with specific option
cdrecord --scanbus # scan SCSI bus
dd if=/dev/hdc | md5sum # compute MD5 of CD22. Network (Ethernet and Wi‑Fi)
ifconfig eth0 # show Ethernet config
ifup eth0 # enable interface
ifdown eth0 # disable interface
ifconfig eth0 192.168.1.1 netmask 255.255.255.0 # set static IP
ifconfig eth0 promisc # enable promiscuous mode
dhclient eth0 # obtain IP via DHCP
route -n show # display routing table
route add -net 0/0 gw IP_Gateway # set default gateway
route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1 # static route
route del 0/0 gw IP_Gateway # delete default route
echo "1" > /proc/sys/net/ipv4/ip_forward # enable IP forwarding
hostname show # display system hostname
host www.example.com # resolve hostname to IP
nslookup www.example.com # DNS lookup
ip link show # show all interfaces
mii-tool eth0 # show link status
ethtool eth0 # show NIC statistics
netstat -tup # list active connections with PID
netstat -tupl # list listening services with PID
tcpdump tcp port 80 # capture HTTP traffic
iwlist scan # list wireless networks
iwconfig eth1 # show wireless interface config
hostname # show hostname
host www.example.com # resolve name
nslookup www.example.com # resolve name
whois www.example.com # query WHOIS database23. List Directory Contents
ls -a # show all files, including hidden
ls -l # detailed list
ls -R # recursive list
ls -ld # list directory/link info
ctrl+r # search command history
pwd # print working directory24. Determine File Type
file filename # display file type25. Copy Files and Directories
cp source destination # copy file or directory
cp -r src_dir dest_dir # recursive copy of directory tree26. Common System Commands
date # view or set system date/time
date -s "YYYY-MM-DD HH:MM:SS" # set date/time
hwclock # display hardware clock (requires root)
cal # display calendar
cal 4 2004 # April 2004 calendar
cal -y 2003 # full year 2003 calendar
uptime # show system uptime
echo "text" # display text, can append with >>
cat file1 # display file content
cat file1 file2 > readme.txt # concatenate files
cat file1 | more # paginate output
cat file1 >> test1.txt # append to file
head -n 5 file1 # first 5 lines
tail -n 5 file1 # last 5 lines
tail -f /var/log/messages # follow log file
more file1 # page forward only
less file1 # page forward and backward
less file1 # exit with q
ls -al | more # long list with pagination
ls -al | less # long list with less
lspci -v # list PCI devices verbosely
lsusb -v # list USB devices verbosely
lsmod # list loaded kernel modules
shutdown -h now # immediate shutdown
shutdown -h +10 # shutdown in 10 minutes
shutdown 23:30 -h # shutdown at 23:30
shutdown -r now # immediate reboot
poweroff # immediate power off
reboot # immediate reboot
zip file.zip file1 # create zip archive
unzip file.zip # extract zip archive
gzip file1 # compress with gzip
tar -cvf archive.tar file1 # create tar archive
tar -xvf archive.tar # extract tar archive
tar -cvzf backup.tar.gz /etc # create gzip‑compressed tarball
tar -tf archive.tar # list tar contents
tar -xvfz archive.tar.gz # extract gzip tarball27. VIM Editor
vim filename # open file in VIM (creates if not exist)
:q # quit VIM
i # insert mode (before cursor)
o # insert new line below cursor
dd # delete current line
yy # yank (copy) current line
5yy # yank 5 lines
p # paste after cursor
u # undo last change
r # replace character under cursor
/pattern # search for pattern
:w # write (save) file
:q! # quit without saving
:x # write and quit (same as :wq)
:set number # show line numbers
:!command # execute external command
:sh # drop to shell (exit with ctrl+d)28. RPM Package Management Commands
rpm -ivh package.rpm # install package
rpm -e package_name # erase package
rpm -Uvh package.rpm # upgrade package
rpm -Fvh package.rpm # upgrade already‑installed package
rpm -qa # list all installed packages
rpm -qa | grep httpd # filter installed packages
rpm -qi package_name # query detailed info
rpm -ql package_name # list files provided by package
rpm -qc package_name # list config files of package
rpm -q --whatrequires package_name# packages that depend on this one
rpm -q --whatprovides package_name # what provides this capability
rpm -q --scripts package_name # show install/remove scripts
rpm -q --changelog package_name # show changelog
rpm -qf /etc/httpd/conf/httpd.conf# find owning package
rpm -qp package.rpm -l # list files in an uninstalled RPM
rpm --import /path/to/key # import GPG key
rpm --checksig package.rpm # verify signature
rpm -V package_name # verify size, permissions, MD5, timestamps
rpm -Va # verify all installed packages (caution)
rpm -Vp package.rpm # verify uninstalled package
rpm2cpio package.rpm | cpio -idmv # extract files from RPM
rpmbuild --rebuild package.src.rpm # rebuild source RPMWritten by
Linux Tech Enthusiast
Focused on sharing practical Linux technology content, covering Linux fundamentals, applications, tools, as well as databases, operating systems, network security, and other technical knowledge.
0 followers
Reader feedback
How this landed with the community
Rate this article
Was this worth your time?
Discussion
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
