Essential Linux Command Cheat Sheet: Over 100 Commands Every Sysadmin Should Know
A comprehensive Linux command reference covering basic system information, file and directory management, searching, mounting, disk usage, user and group administration, permissions, archiving, package management, networking, backup, and many other essential operations for system administrators.
Today we present a very complete Linux command summary that includes the most frequently used operations in daily work.
1. Basic Commands
uname -m # Show processor architecture
uname -r # Show kernel version
arch # Show processor architecture
cat /proc/cpuinfo # Display CPU information
cat /proc/interrupts # Show interrupts
cat /proc/meminfo # Check memory usage
cat /proc/swaps # Show swap usage
cat /proc/version # Show kernel version
cat /proc/net/dev # Show network adapters and statistics
cat /proc/mounts # Show mounted filesystems
lspci -tv # List PCI devices
lsusb -tv # Show USB devices
date # Show system date
cal 2007 # Show calendar for 2007
date 041217002007.00 # Set date and time (MMDDhhmmYY.ss)
clock -w # Save time to BIOS2. Shutdown
shutdown -h now # Power off immediately (1)
init 0 # Power off (2)
shutdown -h hours:minutes & # Schedule shutdown
shutdown -c # Cancel scheduled shutdown
shutdown -r now # Reboot (1)
reboot # Reboot (2)
logout # Log out3. Files and Directories
cd /home # Change to /home directory
cd .. # Go up one level
cd ../.. # Go up two levels
cd ~user1 # Change to user1's home directory
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 (1)
lstree # Tree view (2)
mkdir dir1 # Create directory dir1
mkdir dir1 dir2 # Create two directories
mkdir -p /tmp/dir1/dir2 # Create directory tree
rm -f file1 # Delete file1
rmdir dir1 # Remove empty directory dir1
rm -rf dir1 # Remove directory and its contents
mv dir1 new_dir # Rename/move directory
cp file1 file2 # Copy file
cp dir/* . # Copy all files from dir to current directory
cp -a /tmp/dir1 . # Copy directory preserving attributes
ln -s file1 lnk1 # Create symbolic link
ln file1 lnk1 # Create hard link
touch -t 0712250000 file1 # Set timestamp (YYMMDDhhmm)4. File Search
find / -name file1 # Search from root for file1
find / -user user1 # Find files owned by user1
find /home/user1 -name *.bin # Search .bin files in /home/user1
find /usr/bin -type f -atime +100 # Files not accessed in last 100 days
find /usr/bin -type f -mtime -10 # Files modified within 10 days
find / -name *.rpm -exec chmod 755 {} \; # Change permissions of .rpm files
find / -xdev -name *.rpm # Search .rpm files ignoring removable media
locate *.ps # Find .ps files (run updatedb first)
whereis halt # Locate binary, source, man page for halt
which halt # Show full path of halt5. Mount a Filesystem
mount /dev/hda2 /mnt/hda2 # Mount partition hda2
umount /dev/hda2 # Unmount hda2
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/iso # 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
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
dpkg-query -W -f='${Installed-Size;10}\t${Package}n' | sort -k1,1n # List installed DEB packages by size7. Users and Groups
groupadd group_name
groupdel group_name
groupmod -n new_group_name old_group_name
useradd -c "Name Surname" -g admin -d /home/user1 -s /bin/bash user1
useradd user1
userdel -r user1
usermod -c "User FTP" -g system -d /ftp/user1 -s /bin/nologin user1
passwd
passwd user1
chage -E 2005-12-31 user1
pwck
grpck
newgrp group_name8. File Permissions
chmod ugo+rwx directory1
chmod go-rwx directory1
chown user1 file1
chown -R user1 directory1
chgrp group1 file1
chown user1:group1 file1
find / -perm -u+s # List files with SUID
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
chmod -x file_path # Remove execute permission
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 # Append-only
chattr +c file1 # Compress automatically
chattr +d file1 # Exclude from backups
chattr +i file1 # Immutable
chattr +s file1 # Secure deletion
chattr +S file1 # Write changes immediately to disk
chattr +u file1 # Undelete
lsattr10. Pack and Compress Files
bunzip2 file1.bz2
bzip2 file1
gunzip file1.gz
gzip file1
gzip -9 file1
rar a file1.rar test_file
rar a file1.rar file1 file2 dir1
rar x file1.rar
unrar x file1.rar
tar -cvf archive.tar file1
tar -cvf archive.tar file1 file2 dir1
tar -tf archive.tar
tar -xvf archive.tar
tar -xvf archive.tar -C /tmp
tar -cvfj archive.tar.bz2 dir1
tar -xvfj archive.tar.bz2
tar -cvfz archive.tar.gz dir1
tar -xvfz archive.tar.gz
zip file1.zip file1
zip -r file1.zip file1 file2 dir1
unzip file1.zip11. RPM Packages
rpm -ivh package.rpm
rpm -ivh --nodeps package.rpm
rpm -U package.rpm
rpm -F package.rpm
rpm -e package_name.rpm
rpm -qa
rpm -qa | grep httpd
rpm -qi package_name
rpm -qg "System Environment/Daemons"
rpm -ql package_name
rpm -qc package_name
rpm -q package_name --whatrequires
rpm -q package_name --whatprovides
rpm -q package_name --scripts
rpm -q package_name --changelog
rpm -qf /etc/httpd/conf/httpd.conf
rpm -qp package.rpm -l
rpm --import /media/cdrom/RPM-GPG-KEY
rpm --checksig package.rpm
rpm -qa gpg-pubkey
rpm -V package_name
rpm -Va
rpm -Vp package.rpm
rpm2cpio package.rpm | cpio --extract --make-directories *bin*
rpm -ivh /usr/src/redhat/RPMS/`arch`/package.rpm
rpmbuild --rebuild package_name.src.rpm12. YUM Package Manager
yum install package_name
yum localinstall package_name.rpm
yum update package_name.rpm
yum update package_name
yum remove package_name
yum list
yum search package_name
yum clean packages
yum clean headers
yum clean all13. DEB Packages
dpkg -i package.deb
dpkg -r package_name
dpkg -l
dpkg -l | grep httpd
dpkg -s package_name
dpkg -L package_name
dpkg --contents package.deb
dpkg -S /bin/ping
apt-get install package_name
apt-cdrom install package_name
apt-get update
apt-get upgrade
apt-get remove package_name
apt-get check
apt-get clean
apt-cache search searched-package14. Character Set and File Format Conversion
dos2unix filedos.txt fileunix.txt
unix2dos fileunix.txt filedos.txt
recode ..HTML < page.txt > page.html
recode -l | more15. File System Analysis
badblocks -v /dev/hda1
fsck /dev/hda1
fsck.ext2 /dev/hda1
e2fsck /dev/hda1
e2fsck -j /dev/hda1
fsck.ext3 /dev/hda1
fsck.vfat /dev/hda1
fsck.msdos /dev/hda1
dosfsck /dev/hda116. Initialize a Filesystem
mkfs /dev/hda1
mke2fs /dev/hda1
mke2fs -j /dev/hda1 # ext3
mkfs -t vfat 32 -F /dev/hda1 # FAT32
fdformat -n /dev/fd0 # Format floppy
mkswap /dev/hda317. SWAP Filesystem
mkswap /dev/hda3
swapon /dev/hda3
swapon /dev/hda2 /dev/hdb318. Backup
dump -0aj -f /tmp/home0.bak /home
dump -1aj -f /tmp/home0.bak /home
restore -if /tmp/home0.bak
rsync -rogpav --delete /home /tmp
rsync -rogpav -e ssh --delete /home ip_address:/tmp
rsync -az -e ssh --delete ip_addr:/home/public /home/local
rsync -az -e ssh --delete /home/local ip_addr:/home/public
dd bs=1M if=/dev/hda | gzip | ssh user@ip_addr 'dd of=hda.gz'
dd if=/dev/sda of=/tmp/file1
tar -Puf backup.tar /home/user
( cd /tmp/local/ && tar c . ) | ssh -C user@ip_addr 'cd /home/share/ && tar x -p'
( tar c /home ) | ssh -C user@ip_addr 'cd /home/backup-home && tar x -p'
tar cf - . | (cd /tmp/backup ; tar xf - )
find /home/user1 -name "*.txt" | xargs cp -av --target-directory=/home/backup/ --parents
find /var/log -name "*.log" | tar cv --files-from=- | bzip2 > log.tar.bz2
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 floppy19. CD-ROM
cdrecord -v gracetime=2 dev=/dev/cdrom -eject blank=fast -force # Erase rewritable CD
mkisofs /dev/cdrom > cd.iso
mkisofs /dev/cdrom | gzip > cd_iso.gz
mkisofs -J -allow-leading-dots -R -V "Label CD" -iso-level 4 -o ./cd.iso data_cd
cdrecord -v dev=/dev/cdrom cd.iso
gzip -dc cd_iso.gz | cdrecord dev=/dev/cdrom -
mount -o loop cd.iso /mnt/iso
cd-paranoia -B
cd-paranoia -- "-3"
cdrecord --scanbus
dd if=/dev/hdc | md5sum20. Network
ifconfig eth0
ifup eth0
ifdown eth0
ifconfig eth0 192.168.1.1 netmask 255.255.255.0
ifconfig eth0 promisc
dhclient eth0
route -n show
route add -net 0/0 gw IP_Gateway
route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1
route del 0/0 gw IP_gateway
echo "1" > /proc/sys/net/ipv4/ip_forward
hostname show
host www.example.com
nslookup www.example.com
ip link show
mii-tool eth0
ethtool eth0
netstat -tup
netstat -tupl
tcpdump tcp port 80
iwlist scan
iwconfig eth1
hostname
host www.example.com
nslookup www.example.com
whois www.example.com21. List Directory Contents
ls -a # Show all files including hidden
ls -l # Detailed list
ls -R # Recursive
ls -ld # Show directory/link info
ctrl+r # Search command history
pwd # Show current directory22. View File Type
file filename23. Copy Files and Directories
cp source_file target_file
cp -r source_dir target_dir
cp -v source_file target_file24. Modify File Timestamps
touch filename # Create empty file or update timestamps
touch -d 20040210 filename # Set specific date25. Move or Rename Files
mv source target
mv a.txt b.txt # Rename
mv file ../ # Move up one directory26. Delete Files
rm file1
rm -i file1 # Interactive delete
rm -r dir1 # Recursive delete (files and subdirs)
rm -f *.txt # Force delete without prompts27. Create Directories
mkdir dir1
mkdir -p dir1/dir2 # Create nested directories28. Remove Directories
rmdir dir1 # Remove empty directory
rm -r dir1 # Remove directory and contents
rmdir -p dir1/dir2 # Remove dir2 and parent if empty29. Search
find / -name "*.txt"
grep "pattern" file.txt
locate keyword
which command30. VIM
vim filename # Open file in VIM
:q # Quit VIM31. VIM Modes
# Command mode (default): i, o, dd, yy, p, u, r, /, etc.
# Insert mode: press i to insert text, Esc to return.
# Ex mode: press : to enter, then :w (save), :q (quit), :wq (save & quit), :x, :set number, :!command, :sh32. RPM Package Management Commands
# Install
rpm -ivh package.rpm
# Delete
rpm -e package_name
# Upgrade
rpm -Uvh package.rpm
# Update
rpm -Fvh package.rpm
# Query
rpm -q package_name
rpm -ql package_name
rpm -qi package_nameSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
