Linux Command Reference
About this reference This is a comprehensive reference of Linux commands organized by category. Optimized for Obsidian with command syntax highlighting and clean organization.
1. User and Group Management
useradd # Add a new user
usermod # Modify user account
userdel # Delete a user
groupadd # Add a new group
groupdel # Delete a group
chgrp # Change group ownership of a file
passwd # Change user password
who # Who is logged in
2. File and Directory Management
ls # List directory contents
cd # Change directory
pwd # Print working directory
mkdir # Make a new directory
rmdir # Remove a directory
rm # Remove files or directories
cp # Copy files or directories
mv # Move or rename files or directories
touch # Create empty files
find # Search for file in a directory hierarchy
locate # Find files by name
3. File Management
cat # Concatenate and display file contents
more # View file content page by page
less # View file content with navigation
head # View the first part of a file
tail # View the last part of a file
nano # Text editor to edit files
vi # Text editor to edit files
touch # Create an empty file or update file timestamp
ln # Create hard or symbolic links
file # Determine file type
stat # Display file or file system status
find # Search for files in a directory hierarchy
locate # Find files by name (using a database)
updatedb # Update the database used by locate
xargs # Build and execute command lines from standard input
4. File Permissions and Ownership
chmod # Change file permissions
chown # Change file owner and group
chgrp # Change group ownership
umask # Set file creation mask
getfacl # Get file access control lists (ACL)
setfacl # Set file access control lists (ACL)
ls -l # List files with detailed permissions, owner, and group
stat # Display file or file system status
acl # View or modify Access Control Lists (ACL) on files
5. Disk Management
df # Display free disk space
du # Estimate file space usage
fdisk # Partition table manipulator
parted # A tool for creating and managing disk partitions
lsblk # List information about block devices
blkid # Find or display block device attributes
mount # Mount a file system
umount # Unmount a file system
mkfs # Create a file system
fsck # Check and repair file systems
tune2fs # Adjust tunable file system parameters
resize2fs # Resize an ext2, ext3, or ext4 file system
lvcreate # Create a logical volume
vgcreate # Create a volume group
pvcreate # Prepare a physical volume for LVM
lsattr # List file attributes on a file system
chattr # Change file attributes on a file system
6. Process Management
ps # Display current processes
top # Display dynamic process information
htop # Interactive process viewer
kill # Terminate a process by ID
killall # Kill all processes by name
bg # Resume a suspended process in the background
fg # Bring a process to the foreground
nice # Set process priority
renice # Change the priority of running processes
jobs # List active jobs
pgrep # Search for processes by name or other attributes
pkill # Kill processes by name or other attributes
pstree # Display processes in a tree format
lsof # List open files and the processes that opened them
strace # Trace system calls and signals
timeout # Run a command with a time limit
watch # Execute a program periodically and show output
7. Network Management
ifconfig # Display and configure network interfaces
ip a # Show all network interfaces and their IPs
ip r # Display the routing table
ip link set <interface> up/down # Enable or disable a network interface
ping <host> # Send ICMP echo request to check connectivity
traceroute <host> # Trace the route packets take to a network host
netstat -tulnp # Show open ports and listening services
ss -tulnp # Display socket statistics and listening services
hostname -I # Show the system's IP address
dig <domain> # Query DNS records
nslookup <domain> # Lookup DNS details
whois <domain> # Get domain registration details
curl -I <URL> # Fetch HTTP headers from a website
wget <URL> # Download files from the web
scp <file> user@host:/path # Securely copy files over SSH
rsync -avz <src> <dest> # Sync files between local and remote locations
tcpdump -i eth0 # Capture network packets on an interface
nmap <IP> # Scan a network for open ports
8. System and Monitoring
uptime # Show system uptime and load average
dmesg # Print system boot and hardware logs
free -m # Display memory usage in MB
vmstat # Report system performance statistics
iostat # Display CPU and disk I/O statistics
mpstat # Show CPU usage per core
top # Display dynamic process and system information
htop # Interactive process and resource monitoring
sar -u 5 10 # Monitor CPU usage at 5-second intervals
iotop # Display disk read/write usage per process
lsof # List open files by processes
watch -n 2 <command> # Run a command every 2 seconds
journalctl -xe # View system logs with extended details
systemctl status <service> # Check the status of a service
service <service> status # View service status (legacy systems)
df -h # Show disk space usage in a human-readable format
du -sh <directory> # Display the size of a directory
ps aux --sort=-%mem # List processes sorted by memory usage
netstat -tulnp # Show active network connections and listening services
9. Text Processing
cat <file> # Display file contents
tac <file> # Display file contents in reverse order
head -n <num> <file> # Show the first <num> lines of a file
tail -n <num> <file> # Show the last <num> lines of a file
tail -f <file> # Continuously display new lines in a file
grep '<pattern>' <file> # Search for a pattern in a file
grep -r '<pattern>' <directory> # Recursively search for a pattern in a directory
awk '{print $1, $2}' <file> # Process and extract columns from a file
sed 's/old/new/g' <file> # Replace text in a file
cut -d':' -f1 <file> # Extract specific fields from a file
sort <file> # Sort file contents
uniq <file> # Remove duplicate lines from a file
wc -l <file> # Count lines in a file
wc -w <file> # Count words in a file
wc -c <file> # Count bytes in a file
tr 'a-z' 'A-Z' <file> # Convert lowercase to uppercase
diff <file1> <file2> # Compare two files line by line
cmp <file1> <file2> # Compare two files byte by byte
tee <file> # Read from standard input and write to both a file and standard output
10. Package Management
Debian-based systems Ubuntu, Debian, and derivatives
apt update # Update package lists
apt upgrade # Upgrade all installed packages
apt install <package> # Install a package
apt remove <package> # Remove a package
apt purge <package> # Remove a package and its config files
dpkg -i <package>.deb # Install a .deb package
dpkg -r <package> # Remove a package installed via dpkg
dpkg -l # List installed packages
apt-cache search <package> # Search for a package
apt autoremove # Remove unnecessary packages
apt clean # Clear the package cache
RHEL-based systems CentOS, Rocky Linux, AlmaLinux, Fedora
yum update # Update installed packages (for older systems)
dnf update # Update installed packages (for newer systems)
yum install <package> # Install a package
dnf install <package> # Install a package (newer distros)
yum remove <package> # Remove a package
dnf remove <package> # Remove a package (newer distros)
rpm -ivh <package>.rpm # Install an .rpm package
rpm -e <package> # Remove an installed .rpm package
yum list installed # List installed packages
dnf list installed # List installed packages (newer distros)
yum search <package> # Search for a package
dnf search <package> # Search for a package (newer distros)
yum clean all # Clean cached package data
11. Archive and Compression
Working with tar files
tar -cvf archive.tar <files> # Create a tar archive
tar -xvf archive.tar # Extract a tar archive
tar -tvf archive.tar # List files in a tar archive
tar -czvf archive.tar.gz <files> # Create a compressed tar.gz archive
tar -xzvf archive.tar.gz # Extract a tar.gz archive
tar -cJvf archive.tar.xz <files> # Create a tar.xz archive
tar -xJvf archive.tar.xz # Extract a tar.xz archive
Working with zip files
zip archive.zip <files> # Create a zip archive
unzip archive.zip # Extract a zip archive
unzip -l archive.zip # List contents of a zip file
zip -r archive.zip <directory> # Zip a directory
Working with gzip & bzip2
gzip <file> # Compress a file using gzip
gunzip <file>.gz # Decompress a gzip file
bzip2 <file> # Compress a file using bzip2
bunzip2 <file>.bz2 # Decompress a bzip2 file
12. Shutdown and Reboot
shutdown -h now # Shutdown the system immediately
shutdown -h +10 # Shutdown the system in 10 minutes
shutdown -h 22:00 # Schedule shutdown at 10:00 PM
shutdown -c # Cancel a scheduled shutdown
poweroff # Immediately power off the system
halt # Halt the system
reboot # Reboot the system immediately
shutdown -r now # Reboot the system immediately
shutdown -r +5 # Reboot the system in 5 minutes
systemctl reboot # Reboot using systemd
13. Task Scheduling
crontab -e # Edit cron jobs for the current user
crontab -l # List scheduled cron jobs
crontab -r # Remove all cron jobs for the current user
crontab -u <user> -l # List cron jobs for a specific user
at <time> # Schedule a command to run at specified time
14. System Diagnostics and Troubleshooting
journalctl -xe # View detailed system logs
journalctl -f # Follow live logs in real-time
journalctl --since "1 hour ago" # View logs from the last hour
dmesg | less # View system boot logs
dmesg | grep error # Check for errors in system logs
cat /var/log/syslog # View general system logs (Debian-based)
cat /var/log/messages # View general system logs (RHEL-based)
uptime # Show system uptime and load
free -m # Display available and used memory in MB
top # Monitor real-time CPU, memory, and process usage
htop # Interactive system monitoring (if installed)
vmstat 1 5 # Display system performance stats
iostat # Show CPU and disk usage statistics
Common Command Combinations
Finding large files:
find / -type f -size +100M -exec ls -lh {} \; | sort -k5 -hr
Monitoring real-time logs:
tail -f /var/log/syslog | grep ERROR
System performance snapshot:
echo "Memory:"; free -h; echo -e "\nDisk:"; df -h; echo -e "\nLoad:"; uptime