Operations 39 min read
Essential Linux Command Cheat Sheet for System Administrators
This comprehensive guide lists essential Linux commands for system information, shutdown, file management, searching, mounting, disk usage, user and group handling, permissions, special attributes, packaging, RPM/YUM/DEB management, network utilities, and Vim editing, providing clear examples and options for each task.
Efficient Ops
Efficient Ops
1. Basic Commands
<code>uname -m # Show machine architecture
uname -r # Show kernel version
dmidecode -q # Show hardware components
hdparm -i /dev/hda # List disk characteristics
hdparm -tT /dev/sda # Perform test read on disk
arch # Show machine architecture
cat /proc/cpuinfo # Display CPU info
cat /proc/interrupts # Show interrupts
cat /proc/meminfo # Check memory usage
cat /proc/swaps # List active swap spaces
cat /proc/version # Show kernel version
cat /proc/net/dev # Show network adapters and statistics
cat /proc/mounts # List mounted filesystems
lspci -tv # List PCI devices
lsusb -tv # Show USB devices
date # Display system date
cal 2007 # Show calendar for 2007
date 041217002007.00 # Set date and time (MMDDhhmmYY.ss)
clock -w # Save system time to BIOS</code>2. Shutdown
<code>shutdown -h now # Power off now (method 1)
init 0 # Power off now (method 2)
telinit 0 # Power off now (method 3)
shutdown -h HH:MM # Schedule shutdown
shutdown -c # Cancel scheduled shutdown
shutdown -r now # Reboot now (method 1)
reboot # Reboot now (method 2)
logout # Log out</code>3. Files and Directories
<code>cd /home # Change to /home directory
cd .. # Go up one level
cd ../.. # Go up two levels
cd ~ # Go to personal home directory
cd ~user1 # Switch to another user's home
cd - # Return to previous directory
pwd # Show current working directory
ls # List files in current directory
ls -F # List with file type indicators
ls -l # Detailed list
ls -a # Show hidden files
ls *[0-9]* # List files containing numbers
tree # Tree view of directories (method 1)
lstree # Tree view (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 # Remove directory and its contents
rm -rf dir1 dir2 # Remove two directories recursively
mv dir1 new_dir # Rename or move directory
cp file1 file2 # Copy file1 to file2
cp dir/* . # Copy all files from dir to current directory
cp -a /tmp/dir1 . # Archive copy of dir1 to current directory
ln -s file1 link1 # Create symbolic link
ln file1 link1 # Create hard link
touch -t 0712250000 file1 # Change timestamp (YYMMDDhhmm)
file file1 # Show MIME type of file
iconv -l # List known encodings
iconv -f from -t to input > output # Convert file encoding
find . -maxdepth 1 -name *.jpg -exec convert "{}" -resize 80x60 "thumbs/{}" \; # Batch resize images</code>4. File Search
<code>find / -name file1 # Search from root
find / -user user1 # Search files owned by user1
find /home/user1 -name *.bin # Search .bin files in a directory
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 '{}' \; # Change permissions of .rpm files
find / -xdev -name *.rpm # Search .rpm ignoring removable devices
locate *.ps # Locate .ps files (requires updatedb)
whereis halt # Locate binary, source, man page
which halt # Show full path of executable</code>5. Mount a Filesystem
<code>mount /dev/hda2 /mnt/hda2 # Mount partition hda2
umount /dev/hda2 # Unmount partition hda2
fuser -km /mnt/hda2 # Force unmount if busy
umount -n /mnt/hda2 # Unmount without updating /etc/mtab
mount /dev/fd0 /mnt/floppy # Mount floppy
mount /dev/cdrom /mnt/cdrom # Mount CD-ROM/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
mount /dev/sda1 /mnt/usbdisk # Mount USB flash drive
mount -t smbfs -o username=user,password=pass //WinClient/share /mnt/share # Mount Windows share</code>6. Disk Space
<code>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 -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 DEBs by size</code>7. Users and Groups
<code>groupadd group_name # Create new group
groupdel group_name # Delete group
groupmod -n new old # Rename group
useradd -c "Name Surname" -g admin -d /home/user1 -s /bin/bash user1 # Add user with details
useradd user1 # Simple user add
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 user1 # Change user password (root only)
chage -E 2005-12-31 user1 # Set password expiration date
pwck # Verify /etc/passwd format
grpck # Verify /etc/group format
newgrp group_name # Switch to new primary group</code>8. File Permissions
<code>ls -lh # Show permissions in long format
chmod ugo+rwx directory1 # Give read/write/execute to all
chmod go-rwx directory1 # Remove rwx from group and others
chown user1 file1 # Change file owner
chown -R user1 directory1 # Recursively change owner
chgrp group1 file1 # Change group ownership
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 o+t /home/public # Set sticky bit
chmod +x file # Add execute permission
chmod -x file # Remove execute permission</code>9. Special File Attributes
<code>chattr +a file1 # Append‑only
chattr +c file1 # Auto‑compress
chattr +d file1 # Exclude from dump
chattr +i file1 # Immutable
chattr +s file1 # Secure delete
chattr +S file1 # Synchronous updates
chattr +u file1 # Undelete support
lsattr # List special attributes</code>10. Packing and Compression
<code>bunzip2 file1.bz2
bzip2 file1
gunzip file1.gz
gzip file1
gzip -9 file1
rar a file1.rar test_file
rar x file1.rar
unrar x file1.rar
tar -cvf archive.tar file1
tar -tf archive.tar
tar -xvf archive.tar
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.zip</code>11. RPM Packages (Fedora/RedHat)
<code>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 -V package_name
rpm -Va
rpm -Vp package.rpm
rpm2cpio package.rpm | cpio --extract --make-directories *bin*</code>12. YUM Package Manager
<code>yum install package_name
yum localinstall package.rpm
yum update package_name
yum remove package_name
yum list
yum search package_name
yum clean packages
yum clean headers
yum clean all</code>13. DEB Packages (Debian/Ubuntu)
<code>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-get update
apt-get upgrade
apt-get remove package_name
apt-get clean
apt-cache search searched-package</code>14. View File Content
<code>cat file1
tac file1
more file1
less file1
head -2 file1
tail -2 file1
tail -f /var/log/messages</code>15. Text Processing
<code>cat file1 file2 | command > output.txt
grep pattern /var/log/messages
sed 's/old/new/g' file.txt
awk '{print $1}' file.txt
sort file.txt | uniq
comm -1 file1 file2
...</code>16. Character Set Conversion
<code>dos2unix filedos.txt fileunix.txt
unix2dos fileunix.txt filedos.txt
recode ..HTML < page.txt > page.html
recode -l | more</code>17. Filesystem Analysis
<code>badblocks -v /dev/hda1
fsck /dev/hda1
fsck.ext2 /dev/hda1
fsck.ext3 /dev/hda1
fsck.vfat /dev/hda1</code>18. Initialise a Filesystem
<code>mkfs /dev/hda1
mke2fs /dev/hda1
mke2fs -j /dev/hda1
mkfs -t vfat 32 -F /dev/hda1
fdformat -n /dev/fd0
mkswap /dev/hda3</code>19. SWAP Filesystem
<code>mkswap /dev/hda3
swapon /dev/hda3
swapon /dev/hda2 /dev/hdb3</code>20. Backup
<code>dump -0aj -f /tmp/home0.bak /home
restore -if /tmp/home0.bak
rsync -rogpav --delete /home /tmp
rsync -az -e ssh --delete /home user@remote:/tmp
dd if=/dev/hda | gzip | ssh user@host '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@host 'cd /home/share && tar x -p'
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</code>21. Optical Media
<code>cdrecord -v dev=/dev/cdrom cd.iso
mkisofs /dev/cdrom > cd.iso
mount -o loop cd.iso /mnt/iso
cd-paranoia -B
dd if=/dev/hdc | md5sum</code>22. Network (Ethernet & Wi‑Fi)
<code>ifconfig eth0
ifup eth0
ifdown eth0
ifconfig eth0 192.168.1.1 netmask 255.255.255.0
ifconfig eth0 promisc
dhclient eth0
route -n
route add -net 0/0 gw IP_Gateway
netstat -tup
tcpdump tcp port 80
iwlist scan
iwconfig eth1
hostname
nslookup www.example.com
whois www.example.com</code>23. List Directory Contents
<code>ls -a
ls -l
ls -R
ls -ld
pwd</code>24. Determine File Type
<code>file filename</code>25. Copy, Move, Delete Operations
<code>cp source dest
cp -r src_dir dest_dir
mv old new
rm file
rm -r dir
rmdir dir
mkdir dir
mkdir -p a/b/c
ln -s target link
ln target link</code>26. Common System Commands
<code>date
hwclock
cal
uptime
echo "text"
cat file
more file
less file
head -n file
tail -n file
tail -f file</code>27. VIM Editor
<code>:q # Quit Vim
i # Insert mode
Esc # Return to command mode
dd # Delete line
yy # Yank (copy) line
p # Paste after cursor
u # Undo
/keyword # Search</code>28. RPM Package Management
<code>rpm -ivh package.rpm # Install
rpm -e package_name # Remove
rpm -Uvh package.rpm # Upgrade
rpm -Fvh package.rpm # Update
rpm -q package_name # Query
rpm -ql package_name # List files
rpm -qi package_name # Info
rpm --import keyfile # Import GPG key</code>Written by
Efficient Ops
This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.
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.