Comprehensive Linux Command Reference

System Information

arch                          # Display machine architecture (1)
uname -m                      # Display machine architecture (2)
uname -r                      # Display kernel version
dmidecode -q                  # Show hardware components (SMBIOS/DMI)
hdparm -i /dev/sda            # List disk architecture features
hdparm -tT /dev/sda           # Perform disk read tests
cat /proc/cpuinfo             # Show 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                          # Display system date
cal 2024                      # Display calendar for 2024
date 041217002024.00          # Set date and time (MMDDhhmmYYYY.ss)
clock -w                      # Save time changes to BIOS

Shutdown, Reboot, and Logout

shutdown -h now               # Shutdown immediately (1)
init 0                        # Shutdown (2)
telinit 0                     # Shutdown (3)
shutdown -h 23:00 &           # Scheduled shutdown
shutdown -c                   # Cancel scheduled shutdown
shutdown -r now               # Reboot (1)
reboot                        # Reboot (2)
logout                        # Log out

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 user1's home directory
cd -                          # Return to previous directory
pwd                           # Show current working directory
ls                            # List directory contents
ls -F                         # List with file type indicators
ls -l                         # Detailed listing
ls -a                         # Include hidden files
ls *[0-9]*                    # List files/dirs containing digits
tree                          # Display tree structure (1)
lstree                        # Display tree structure (2)
mkdir dir1                    # Create directory 'dir1'
mkdir dir1 dir2               # Create two directories
mkdir -p /tmp/dir1/dir2       # Create nested directories
rm -f file1                   # Delete file 'file1'
rmdir dir1                    # Remove empty directory 'dir1'
rm -rf dir1                   # Remove directory 'dir1' and contents
rm -rf dir1 dir2              # Remove two directories with contents
mv dir1 new_dir               # Rename or move directory
cp file1 file2                # Copy file
cp dir/* .                    # Copy all files from directory to current
cp -a /tmp/dir1 .             # Copy directory to current
cp -a dir1 dir2               # Copy directory
ln -s file1 lnk1              # Create symbolic link
ln file1 lnk1                 # Create hard link
touch -t 0712250000 file1     # Modify timestamp (YYMMDDhhmm)
file file1                    # Output file MIME type
iconv -l                      # List known encodings
iconv -f fromEncoding -t toEncoding inputFile > outputFile  # Convert file encoding

File Search

find / -name file1            # Search from root for file/directory
find / -user user1            # Find files owned by user1
find /home/user1 -name "*.bin"  # Search for .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 {} \;  # Find .rpm files and set permissions
find / -xdev -name "*.rpm"    # Find .rpm files excluding removable devices
locate "*.ps"                 # Find .ps files (run updatedb first)
whereis halt                  # Locate binary, source, and man pages
which halt                    # Show full path of executable

Mounting Filesystems

mount /dev/sda2 /mnt/sda2     # Mount partition (ensure /mnt/sda2 exists)
umount /dev/sda2             # Unmount partition
fuser -km /mnt/sda2           # Force unmount when busy
umount -n /mnt/sda2           # Unmount without updating /etc/mtab (useful for read-only)
mount /dev/fd0 /mnt/floppy    # Mount floppy
mount /dev/cdrom /mnt/cdrom   # Mount CD/DVD
mount /dev/sr0 /mnt/cdrecorder # Mount CD-RW/DVD-RW
mount -o loop file.iso /mnt/iso  # Mount ISO image
mount -t vfat /dev/sda5 /mnt/sda5  # Mount FAT32 filesystem
mount /dev/sdb1 /mnt/usb      # Mount USB drive
mount -t cifs -o username=user,password=pass //WinClient/share /mnt/share  # Mount Windows share

Disk Usage

df -h                         # Show mounted partition disk usage
ls -lSr | more                # List files sorted by size
du -sh dir1                   # Estimate disk usage of directory
du -sk * | sort -rn           # Show size of files/directories sorted
rpm -q -a --qf '%10{SIZE}\t%{NAME}\n' | sort -k1,1n  # RPM package sizes (Red Hat)
dpkg-query -W -f='${Installed-Size;10}\t${Package}\n' | sort -k1,1n  # Deb package sizes (Debian/Ubuntu)

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 with 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
passwd                        # Change password
passwd user1                  # Change password for user1 (root only)
chage -E 2025-12-31 user1     # Set password expiration
pwck                          # Verify /etc/passwd format and syntax
grpck                         # Verify /etc/group format and syntax
newgrp group_name             # Log into new group for file creation

File Permissions

ls -lh                        # Show permissions
ls /tmp | pr -T5 -W$COLUMNS   # Display in 5 columns
chmod ugo+rwx directory1      # Add read/write/execute for all
chmod go-rwx directory1       # Remove execute for group and others
chown user1 file1             # Change file owner
chown -R user1 directory1     # Recursively change directory owner
chgrp group1 file1            # Change group
chown user1:group1 file1      # Change owner and group
find / -perm -u+s             # Find SUID files
chmod u+s /bin/file1          # Set SUID bit
chmod u-s /bin/file1          # Remove SUID bit
chmod g+s /home/public        # Set SGID bit on directory
chmod g-s /home/public        # Remove SGID bit
chmod o+t /home/public        # Set sticky bit (only owner can delete)
chmod o-t /home/public        # Remove sticky bit

Special File Attributes

chattr +a file1               # Append-only mode
chattr +c file1               # Auto-compression
chattr +d file1               # Ignored by dump
chattr +i file1               # Immutable (cannot delete/modify)
chattr +s file1               # Secure deletion
chattr +S file1               # Synchronous updates
chattr +u file1               # Undeletable
lsattr                        # Show attributes

Packaging and Comrpession

bunzip2 file1.bz2             # Decompress .bz2
bzip2 file1                   # Compress to .bz2
gunzip file1.gz               # Decompress .gz
gzip file1                    # Compress to .gz
gzip -9 file1                 # Maximum compression
rar a file1.rar test_file     # Create RAR archive
rar a file1.rar file1 file2 dir1  # Add files to RAR
rar x file1.rar               # Extract RAR
unrar x file1.rar             # Extract RAR (alternative)
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 tarball contents
tar -xvf archive.tar          # Extract tarball
tar -xvf archive.tar -C /tmp  # Extract to specific directory
tar -cvfj archive.tar.bz2 dir1  # Create bzip2 compressed tarball
tar -jxvf archive.tar.bz2    # Extract bzip2 tarball
tar -cvfz archive.tar.gz dir1   # Create gzip compressed tarball
tar -zxvf archive.tar.gz      # Extract gzip tarball
zip file1.zip file1           # Create ZIP archive
zip -r file1.zip file1 file2 dir1  # Recursively create ZIP
unzip file1.zip               # Extract ZIP

RPM Package Management (Fedora, Red Hat)

rpm -ivh package.rpm          # Install RPM
rpm -ivh --nodeps package.rpm # Install ignoring dependencies
rpm -U package.rpm            # Update RPM
rpm -F package.rpm            # Refresh RPM
rpm -e package_name           # Remove RPM
rpm -qa                       # List all installed RPMs
rpm -qa | grep httpd          # Search for httpd-related RPMs
rpm -qi package_name          # Show package info
rpm -qg "System Environment/Daemons"  # Show packages in group
rpm -ql package_name          # List files in package
rpm -qc package_name          # List config files
rpm -q --whatrequires package_name  # Show dependencies
rpm -q --whatprovides package_name  # Show size
rpm -q --scripts package_name # Show install/remove scripts
rpm -q --changelog package_name     # Show change history
rpm -qf /etc/httpd/conf/httpd.conf  # Find which package owns file
rpm -qp package.rpm -l       # List files in uninstalled package
rpm --import /media/cdrom/RPM-GPG-KEY  # Import GPG key
rpm --checksig package.rpm   # Verify package integrity
rpm -qa gpg-pubkey           # Check RPM signature
rpm -V package_name          # Verify package
rpm -Va                      # Verify all packages
rpm -Vp package.rpm          # Verify uninstalled package
rpm2cpio package.rpm | cpio --extract --make-directories *bin*  # Extract executable from RPM
rpm -ivh /usr/src/redhat/RPMS/`arch`/package.rpm  # Install built RPM from SRPM
rpmbuild --rebuild package_name.src.rpm  # Build RPM from SRPM

YUM Package Manager (Fedora, Red Hat)

yum install package_name      # Install package
yum localinstall package_name.rpm  # Install local RPM with dependency resolution
yum update package_name       # Update package
yum update                    # Update all packages
yum remove package_name       # Remove package
yum list                      # List installed packages
yum search keyword            # Search repositories
yum clean packages            # Clear package cache
yum clean headers             # Remove header files
yum clean all                 # Clear all cache

DEB Package Management (Debian, Ubuntu)

dpkg -i package.deb           # Install/update deb
dpkg -r package_name          # Remove deb
dpkg -l                       # List installed debs
dpkg -l | grep httpd          # Search for httpd-related debs
dpkg -s package_name          # Show package status
dpkg -L package_name          # List files in package
dpkg --contents package.deb   # List files in uninstalled deb
dpkg -S /bin/ping             # Find which package owns file

APT Package Tools (Debian, Ubuntu)

apt-get install package_name  # Install/update deb
apt-cdrom install package_name  # Install from CD
apt-get update                # Update package list
apt-get upgrade               # Upgrade all packages
apt-get remove package_name   # Remove package
apt-get check                 # Verify dependency integrity
apt-get clean                 # Clear downloaded package cache
apt-cache search keyword      # Search for packages

Viewing File Contents

cat file1                     # Display file from beginning
tac file1                     # Display file in reverse
more file1                    # Page through file
less file1                    # Scrollable file viewer
head -n 2 file1               # Show first 2 lines
tail -n 2 file1               # Show last 2 lines
tail -f /var/log/syslog       # Follow file as it grows

Text Processing

cat file1 | command > result.txt      # Redirect output to new file
cat file1 | command >> result.txt     # Append output to existing file
grep Aug /var/log/messages            # Search for 'Aug' in file
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/old/new/g' example.txt         # Replace 'old' with 'new'
sed '/^$/d' example.txt               # Remove blank lines
sed '/ *#/d; /^$/d' example.txt       # Remove comments and blanks
echo 'example' | tr '[:lower:]' '[:upper:]'  # Convert to uppercase
sed -e '1d' result.txt                # Delete first line
sed -n '/pattern/p'                   # Print lines matching pattern
sed -e 's/ *$//' example.txt          # Remove trailing whitespace
sed -e 's/pattern//g' example.txt     # Delete pattern from text
sed -n '1,5p;5q' example.txt          # Print lines 1-5
sed -n '5p;5q' example.txt            # Print line 5
sed -e 's/00*/0/g' example.txt        # Replace multiple zeroes with single zero
cat -n file1                          # Number lines
cat example.txt | awk 'NR%2==1'       # Print odd 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 both files
sort file1 file2 | uniq               # Union (unique lines)
sort file1 file2 | uniq -u            # Lines unique to each file
sort file1 file2 | uniq -d            # Intersection (common lines)
comm -1 file1 file2                   # Lines only in file2
comm -2 file1 file2                   # Lines only in file1
comm -3 file1 file2                   # Lines common to both

Character Set and File Format Conversion

dos2unix file-windows.txt file-unix.txt   # Convert DOS to Unix line endings
unix2dos file-unix.txt file-windows.txt   # Convert Unix to DOS
recode ..HTML < page.txt > page.html      # Convert text to HTML
recode -l | more                          # List all recode formats

Filesystem Analysis

badblocks -v /dev/sda1        # Check for bad blocks
fsck /dev/sda1                # Check/repair Linux filesystem
fsck.ext2 /dev/sda1           # Check ext2 filesystem
e2fsck /dev/sda1              # Alternative ext2 check
e2fsck -j /dev/sda1           # Check ext3 filesystem
fsck.ext3 /dev/sda1           # Alternative ext3 check
fsck.vfat /dev/sda1           # Check FAT filesystem
fsck.msdos /dev/sda1          # Check DOS filesystem
dosfsck /dev/sda1             # Alternative DOS check

Creating Filesystems

mkfs /dev/sda1                # Create filesystem on partition
mke2fs /dev/sda1              # Create ext2 filesystem
mke2fs -j /dev/sda1           # Create ext3 (journaling) filesystem
mkfs -t vfat -F 32 /dev/sda1  # Create FAT32 filesystem
fdformat -n /dev/fd0          # Format floppy disk
mkswap /dev/sda3              # Create swap space

Swap Management

mkswap /dev/sda3              # Prepare swap partition
swapon /dev/sda3              # Activate swap
swapon /dev/sda2 /dev/sdb3    # Activate multiple swap areas

Backup Commands

dump -0aj -f /tmp/home0.bak /home  # Full backup of /home
dump -1aj -f /tmp/home0.bak /home  # Incremental backup
restore -if /tmp/home0.bak         # Restore from backup
rsync -rogpav --delete /home /tmp  # Synchronize directories locally
rsync -rogpav -e ssh --delete /home user@remote:/tmp  # Sync via SSH
rsync -az -e ssh --delete user@remote:/home/public /home/local  # Pull remote to local
rsync -az -e ssh --delete /home/local user@remote:/home/public  # Push local to remote
dd bs=1M if=/dev/sda | gzip | ssh user@remote 'dd of=sda.gz'  # Backup disk via SSH
dd if=/dev/sda of=/tmp/disk_image  # Backup disk to file
tar -Puf backup.tar /home/user  # Incremental tar backup
( cd /tmp/local && tar c . ) | ssh -C user@remote 'cd /home/share && tar x -p'  # Copy via SSH
tar cf - . | (cd /tmp/backup ; tar xf - )  # Copy preserving permissions
find /home/user1 -name '*.txt' -exec cp -av --target-directory=/home/backup/ --parents {} +  # Find and copy files
find /var/log -name '*.log' | tar cv --files-from=- | bzip2 > logs.tar.bz2  # Archive logs as bz2
dd if=/dev/sda of=/dev/fd0 bs=512 count=1  # Backup MBR to floppy
dd if=/dev/fd0 of=/dev/sda bs=512 count=1  # Restore MBR from floppy

CD/DVD Operations

cdrecord -v gracetime=2 dev=/dev/cdrom -eject blank=fast -force  # Blank rewritable CD
mkisofs /dev/cdrom > cd.iso          # Create ISO from disc
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 from directory
cdrecord -v dev=/dev/cdrom cd.iso    # Burn ISO
gzip -dc cd_iso.gz | cdrecord dev=/dev/cdrom -  # Burn compressed ISO
mount -o loop cd.iso /mnt/iso        # Mount ISO file
cd-paranoia -B                       # Rip audio tracks to WAV
cd-paranoia -- "-3"                  # Rip with specific track range
cdrecord --scanbus                   # Scan SCSI bus
dd if=/dev/sr0 | md5sum             # Verify MD5 of disc

Networking (Ethernet and Wi-Fi)

ifconfig eth0                 # Show eth0 configuration
ifup eth0                     # Enable interface
ifdown eth0                   # Disable interface
ifconfig eth0 192.168.1.1 netmask 255.255.255.0  # Set IP address
ifconfig eth0 promisc         # Enable promiscuous mode for sniffing
dhclient eth0                 # Obtain IP via DHCP
route -n                      # Show routing table
route add default gw 192.168.1.1  # Add default gateway
route add -net 192.168.0.0/16 gw 192.168.1.1  # Add static route
route del default gw 192.168.1.1  # Delete default gateway
echo 1 > /proc/sys/net/ipv4/ip_forward  # Enable IP forwarding
hostname                      # Show hostname
host www.example.com          # DNS lookup
nslookup www.example.com      # Alternative DNS lookup
whois www.example.com         # Whois lookup
ip link show                  # Show all interfaces
mii-tool eth0                 # Show eth0 link status
ethtool eth0                  # Show network card statistics
netstat -tup                  # Show active connections with PIDs
netstat -tupl                 # Show listening services with PIDs
tcpdump tcp port 80           # Capture HTTP traffic
iwlist scan                   # Scan wireless networks
iwconfig wlan0                # Show wireless configuration

Java Process Status (jps)

jps displays Java Virtual Machine process IDs. It requires JAVA_HOME configured; typically located in $JAVA_HOME/bin/jps.

jps                           # List Java processes with main class or JAR
jps -q                        # List only PIDs
jps -m                        # Show arguments passed to main method
jps -l                        # Show full package name or JAR path
jps -v                        # Show JVM arguments
sudo jps                      # Show all users' Java processes
jps 192.168.0.77              # List Java processes on remote host (requires jstatd)

Samba / Windows Networking

nbtscan 192.168.1.100         # NetBIOS name resolution
nmblookup -A 192.168.1.100    # NetBIOS lookup
smbclient -L server           # List remote shares
smbget -Rr smb://server/share  # Download files via SMB
mount -t cifs -o username=user,password=pass //Server/Share /mnt/point  # Mount Windows share

Tags: Linux command-line sysadmin Reference cheatsheet

Posted on Tue, 06 Oct 2026 16:36:35 +0000 by Seraskier