Operations 46 min read

Essential Linux Command Cheat Sheet for System Administration

This article provides a comprehensive, categorized reference of essential Linux commands covering system information, shutdown, file management, searching, mounting, disk usage, user and group handling, permissions, special attributes, compression, package management, networking, backup, and common utilities, helping users quickly locate and apply the right command in daily operations.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Essential Linux Command Cheat Sheet for System Administration

1. Basic Commands

uname -m            # display processor architecture
uname -r            # display kernel version
dmidecode -q        # display hardware components (SMBIOS/DMI)
hdparm -i /dev/hda  # list disk architecture features
hdparm -tT /dev/sda # perform read test on disk
arch                # display processor architecture
cat /proc/cpuinfo   # show CPU info
cat /proc/interrupts# show interrupts
cat /proc/meminfo   # verify memory usage
cat /proc/swaps     # show used swap spaces
cat /proc/version   # display kernel version
cat /proc/net/dev   # show network adapters and statistics
cat /proc/mounts    # list 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 (MMDDhhmmYYYY.ss)
clock -w            # save system time to BIOS

2. Shutdown

shutdown -h now          # power off immediately
init 0                  # power off (alternative)
telinit 0               # power off (alternative)
shutdown -h hh:mm       # schedule shutdown
shutdown -c              # cancel scheduled shutdown
shutdown -r now          # reboot immediately
reboot                  # reboot (alternative)
logout                  # log out

3. Files and Directories

cd /home                # enter /home directory
cd ..                   # go up one level
cd ../..                # go up two levels
cd ~                    # go to home directory
cd ~user1               # go to specific user's home
cd -                    # return to previous directory
pwd                     # show current path
ls                      # list files
ls -F                   # list files with type indicators
ls -l                   # detailed list
ls -a                   # show hidden files
ls *[0-9]*              # show names containing numbers
tree                    # tree view from root
lstree                  # alternative tree view
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
mv dir1 new_dir         # rename or move directory
cp file1 file2          # copy file
cp dir/* .              # copy all files from dir to current directory
cp -a /tmp/dir1 .       # archive copy of dir1
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
iconv -l                # list known encodings
iconv -f fromEnc -t toEnc inputFile > outputFile # convert encoding
find . -maxdepth 1 -name *.jpg -print -exec convert "{}" -resize 80x60 "thumbs/{}" \; # batch resize images

4. File Search

find / -name file1                     # search from root
find / -user user1                    # search files owned by user1
find /home/user1 -name *.bin          # search .bin files in directory
find /usr/bin -type f -atime +100    # find files not accessed in 100 days
find /usr/bin -type f -mtime -10      # find files modified in last 10 days
find / -name *.rpm -exec chmod 755 '{}' \; # change permissions of .rpm files
find / -xdev -name *.rpm              # search .rpm ignoring removable media
locate *.ps                           # locate .ps files (run updatedb first)
whereis halt                          # locate binary, source, man page
which halt                             # show full path of executable

5. Mount a Filesystem

mount /dev/hda2 /mnt/hda2          # mount partition (ensure mount point exists)
umount /dev/hda2                 # unmount partition
fuser -km /mnt/hda2               # force unmount when busy
umount -n /mnt/hda2                # unmount without updating /etc/mtab
mount /dev/fd0 /mnt/floppy        # mount floppy
mount /dev/cdrom /mnt/cdrom       # mount CD/DVD
mount /dev/hdc /mnt/cdrecorder    # mount CD-RW/DVD-RW
mount -o loop file.iso /mnt/cdrom  # mount ISO image
mount -t vfat /dev/hda5 /mnt/hda5 # mount Windows FAT32 filesystem
mount /dev/sda1 /mnt/usbdisk      # mount USB drive
mount -t smbfs -o username=user,password=pass //WinClient/share /mnt/share # mount Windows share

6. 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 files/directories by size
rpm -qa --qf '%10{SIZE}t%{NAME}n' | sort -k1,1n   # list installed RPM packages by size (Fedora/RedHat)
dpkg-query -W -f='${Installed-Size;10}t${Package}n' | sort -k1,1n   # list installed DEB packages by size (Ubuntu/Debian)

7. Users and Groups

groupadd group_name          # create new group
groupdel group_name          # delete group
groupmod -n new_name old_name# rename group
useradd -c "Name Surname" -g admin -d /home/user1 -s /bin/bash user1 # create user in admin group
useradd user1               # create new 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 expiry date
pwck                         # verify /etc/passwd format
grpck                        # verify /etc/group format
newgrp group_name           # switch to new group

8. File Permissions (using "+" to add, "-" to remove)

ls -lh                         # show permissions in human‑readable form
chmod ugo+rwx directory1       # grant read/write/execute to user, group, others
chmod go-rwx directory1        # remove rwx 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
find / -perm -u+s             # list files with SUID bit set
chmod u+s /bin/file1          # set SUID on binary
chmod u-s /bin/file1          # remove SUID
chmod g+s /home/public        # set SGID on directory
chmod g-s /home/public        # remove SGID
chmod o+t /home/public        # set sticky bit on directory
chmod o-t /home/public        # remove sticky bit
chmod +x file                 # add execute permission for all
chmod -x file                 # remove execute permission for all
chmod u+x file                # add execute for owner
chmod g+x file                # add execute for group
chmod o+x file                # add execute for others
chmod ug+x file               # add execute for owner and group
chmod =wx file                # set write and execute, remove read for all
chmod ug=wx file              # set write and execute for owner and group

9. Special File Attributes (using "+" to set, "-" to clear)

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)
chattr +s file1   # secure deletion flag
chattr +S file1   # sync changes to disk immediately after write
chattr +u file1   # allow undeletion
lsattr file1       # display special attributes

10. Archiving and Compression

bunzip2 file1.bz2                # decompress bzip2 file
bzip2 file1                      # compress file with bzip2
gunzip file1.gz                  # decompress gzip 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 -tvf archive.tar              # list contents of tarball
tar -xvf archive.tar              # extract tarball
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 # create zip archive recursively
unzip file1.zip                  # extract zip archive

11. RPM Packages

rpm -ivh package.rpm                 # install RPM package
rpm -ivh --nodeps package.rpm       # install ignoring dependencies
rpm -U package.rpm                   # upgrade without changing config files
rpm -F package.rpm                   # reinstall already installed package
rpm -e package.rpm                   # erase package
rpm -qa                              # list all installed RPMs
rpm -qa | grep httpd                # filter installed RPMs by name
rpm -qi package_name                 # query detailed info
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 it
rpm -q --whatprovides package_name   # show what provides the package
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 package files
rpm -Va                              # verify all installed packages (use with care)
rpm2cpio package.rpm | cpio --extract --make-directories *bin* # run executable from RPM
rpm -ivh /usr/src/redhat/RPMS/`arch`/package.rpm # install built package from source
rpmbuild --rebuild package.src.rpm   # rebuild source RPM

12. YUM Package Manager

yum install package_name                     # download and install RPM
yum localinstall package.rpm                # install local RPM with dependency resolution
yum update package_name.rpm                 # update all installed RPMs
yum update package_name                     # update a specific package
yum remove package_name                     # erase a package
yum list                                    # list all installed packages
yum search package_name                     # search repository for package
yum clean packages                          # clean downloaded packages
yum clean headers                           # clean header files
yum clean all                               # clean all cached data

13. DEB Packages

dpkg -i package.deb               # install or upgrade DEB package
dpkg -r package_name             # remove DEB package
dpkg -l                         # list installed DEB packages
dpkg -l | grep httpd           # filter installed DEB packages
dpkg -s package_name            # show information about installed package
dpkg -L package_name            # list files provided by installed package
dpkg --contents package.deb     # list files in an uninstalled DEB
dpkg -S /bin/ping               # find which DEB provides a file
apt-get install package_name     # install or upgrade DEB package
apt-get update                  # update package index
apt-get upgrade                 # upgrade all installed packages
apt-get remove package_name     # remove DEB package
apt-get check                   # verify package dependencies
apt-get clean                  # clean downloaded package files
apt-cache search searched-package # search package names

14. Viewing File Contents

cat file1                     # display file from start
tac file1                     # display file in reverse order
more file1                    # paginate long file
less file1                    # paginate with forward/backward scrolling
head -2 file1                 # show first two lines
tail -2 file1                 # show last two lines
tail -f /var/log/messages    # follow file updates in real time

15. Text Processing

cat file1 file2 ... | command > file1_out.txt   # pipe output to file
cat file1 | grep pattern > result.txt           # filter with grep
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
sed 's/string1/string2/g' example.txt          # replace string1 with string2
sed '/^$/d' example.txt                        # delete empty lines
sed '/ *#/d; /^$/d' example.txt                # delete comments and empty lines
echo 'example' | tr '[:lower:]' '[:upper:]'   # convert to uppercase
sed -e '1d' result.txt                         # delete first line
sed -n '/string1/p' example.txt                # print lines containing string1
sed -e 's/ *$//' example.txt                    # trim trailing spaces
sed -e 's/string1//g' example.txt              # delete string1
sed -n '1,5p;5q' example.txt                   # show lines 1‑5 then quit
sed -n '5p;5q' example.txt                     # show line 5 then quit
sed -e 's/00*/0/g' example.txt                # replace multiple zeros with single zero
cat -n file1                                    # number lines
cat example.txt | awk 'NR%2==1'               # print odd‑numbered 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 files side by side
paste -d '+' file1 file2                        # merge with '+' delimiter
sort file1 file2                                # sort combined files
sort file1 file2 | uniq                         # unique lines
sort file1 file2 | uniq -u                     # lines unique to one file
sort file1 file2 | uniq -d                     # common lines
comm -1 file1 file2                             # show lines only in file2
comm -2 file1 file2                             # show lines only in file1
comm -3 file1 file2                             # show common lines

16. Character Set Conversion and File Format

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 supported conversions

17. 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/ext3 filesystem
e2fsck -j /dev/hda1                   # check ext3 filesystem 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 filesystem

18. Initialise a Filesystem

mkfs /dev/hda1                         # create filesystem on partition
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 area

19. Swap Filesystem

mkswap /dev/hda3                      # create swap partition
swapon /dev/hda3                      # enable swap
swapon /dev/hda2 /dev/hdb3            # enable two swap partitions

20. 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 user@ip:/tmp # sync over SSH
rsync -az -e ssh --delete /home user@ip:/backup # compressed sync over SSH
dd bs=1M if=/dev/hda | gzip | ssh user@ip 'dd of=hda.gz' # remote backup via SSH
dd if=/dev/sda of=/tmp/file1               # copy disk to file
tar -Puf backup.tar /home/user            # incremental backup
(cd /tmp/local && tar c .) | ssh -C user@ip 'cd /home/share && tar x -p' # copy directory over SSH
(tar c /home) | ssh -C user@ip 'cd /home/backup && tar x -p' # copy entire /home over SSH
tar cf - . | (cd /tmp/backup ; tar xf -)   # local copy preserving permissions
find /home/user1 -name '*.txt' | xargs cp -av --target-directory=/home/backup/ --parents # copy matching 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 floppy

21. Optical Discs

cdrecord -v gracetime=2 dev=/dev/cdrom -eject -blank=fast -force   # erase rewritable CD
mkisofs /dev/cdrom > cd.iso                                      # create ISO image
mkisofs /dev/cdrom | gzip > cd_iso.gz                            # create compressed ISO
mkisofs -J -allow-leading-dots -R -V "Label CD" -iso-level 4 -o ./cd.iso data_cd # create ISO with Joliet and Rock Ridge
cdrecord -v dev=/dev/cdrom cd.iso                                 # burn ISO to CD
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 > track.wav                                         # extract audio tracks to WAV
cd-paranoia -- "-3" > track.wav                                   # extract with -3 option
cdrecord --scanbus                                                # scan SCSI bus
dd if=/dev/hdc | md5sum                                            # compute MD5 of CD

22. 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                         # 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 static route
echo "1" > /proc/sys/net/ipv4/ip_forward # enable IP forwarding
hostname                         # show system hostname
host www.example.com             # resolve hostname to IP
nslookup www.example.com         # resolve hostname to IP
ip link show                     # list interfaces
mii-tool eth0                    # show link status
ethtool eth0                     # show interface statistics
netstat -tup                     # list active connections with PID
netstat -tupl                    # list listening services with PID
tcpdump tcp port 80              # capture HTTP traffic
iwlist scan                      # scan wireless networks
iwconfig eth1                     # show wireless interface config

23. List Directory Contents

ls -a               # show all files, including hidden
ls -l               # detailed list
ls -R               # recursive listing
ls -ld              # list directory itself
ctrl+r              # search command history
pwd                 # show current directory

24. Determine File Type

file file1          # display file type

25. Copy Files and Directories

cp source destination                     # copy file or directory
cp -r src_dir dest_dir                    # recursive copy of directory tree
cp -v src dest                            # verbose copy
cp -a src dest                            # archive copy preserving attributes

26. Common System Commands

26.1 Display Commands

date                # show current date/time
date -s "..."      # set system date/time
hwclock             # show hardware clock (requires root)
cal                 # display calendar
uptime              # show system uptime

26.2 Output and Viewing Commands

echo "text" >> file   # append text to file
cat file               # display file content
cat file | more         # paginate output
cat file >> other      # append file to another
head -n 2 file         # first two lines
tail -n 2 file         # last two lines
tail -f /var/log/...   # follow log updates
more file              # simple pager (forward only)
less file              # pager with forward/backward navigation

26.3 Hardware Information

lspci -v              # list PCI devices with details
lsusb -v              # list USB devices with details
lsmod                 # list loaded kernel modules

26.4 Shutdown and Reboot

shutdown -h now      # immediate power‑off
shutdown -h +10     # power‑off after 10 minutes
shutdown -h 23:30    # power‑off at 23:30
shutdown -r now      # immediate reboot
poweroff              # immediate power‑off
reboot                # immediate reboot

26.5 Archiving and Compression

zip file.zip file          # create zip archive
unzip file.zip             # extract zip archive
gzip file                  # compress with gzip
tar -cvf out.tar files...  # create tar archive
tar -xvf out.tar           # extract tar archive
tar -cvzf backup.tar.gz /etc # create gzip‑compressed tarball

26.6 Search

locate keyword            # fast file locate (requires updatedb)
find . -name "pattern"    # find files by name
find / -name *.conf       # find all .conf files from root
find / -perm 777          # find files with specific permissions
find / -type d            # list all directories
find . -name "a*" -exec ls -l {} \; # execute command on matches

26.7 Miscellaneous

Ctrl+C                 # terminate current command
who / w                # show logged‑in users
dmesg                  # display kernel ring buffer messages
df                     # show filesystem space usage
du                     # estimate directory space usage
free                   # display memory and swap usage

27. VIM Editor

vim file                # open file in VIM
:q                      # quit VIM
:i                      # enter insert mode
:o                      # open new line below
:dd                     # delete current line
:yy                     # yank (copy) current line
:n+yy                   # yank n lines
:p                      # paste after cursor
:u                      # undo last change
:r                      # replace character under cursor
:/pattern               # search for pattern
:! command              # execute shell command
:w                      # write (save) file
:wq or :x               # write and quit
:set number             # show line numbers
:! sh                  # drop to shell (return with Ctrl+D)

28. RPM Package Management Commands

28.1 Install Packages

rpm -ivh package.rpm    # install package with progress bar

28.2 Remove Packages

rpm -e package_name    # erase package (does not remove modified config files)

28.3 Upgrade Packages

rpm -Uvh package.rpm   # upgrade to newer version

28.4 Update Packages

rpm -Fvh package.rpm   # update if older version is present

28.5 Query Packages

rpm -q package_name    # query installed package
rpm -ql package_name   # list files installed by package
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxShellcommand-lineUnixSystem Administrationterminal
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.