Linux Commands Cheat Sheet — 100+ Essential Commands

Published: June 2025 • 20 min read • Category: Linux

Whether you're a beginner setting up your first Linux server or an experienced sysadmin managing dozens of machines, having a reliable command reference is essential. This cheat sheet covers 100+ essential Linux commands organized into clear categories — from basic file operations to advanced networking and process management.

📋 Quick Navigation

  1. File & Directory Commands
  2. Text Processing & Search
  3. File Permissions & Ownership
  4. Process Management
  5. Disk & Storage
  6. Networking Commands
  7. System Information
  8. User Management
  9. SSH & Remote Access
  10. Package Management
  11. Archiving & Compression
  12. Pro Tips & Tricks

1. File & Directory Commands

These are the commands you'll use most frequently — navigating, creating, moving, and inspecting files and directories.

CommandDescription
pwdPrint working directory — shows your current location
lsList directory contents
ls -laList all files (including hidden) with details
ls -lhList files with human-readable sizes
cd /pathChange directory to /path
cd ..Go up one directory
cd ~Go to home directory
cd -Go to previous directory
mkdir dirnameCreate a new directory
mkdir -p a/b/cCreate nested directories
touch file.txtCreate an empty file or update timestamp
cp src dstCopy file or directory
cp -r src/ dst/Copy directory recursively
mv old newMove or rename file/directory
rm file.txtDelete a file
rm -rf dir/Delete directory and all contents recursively
ln -s target linkCreate a symbolic link
find . -name "*.py"Find files matching a pattern
locate filenameQuickly find files (uses database)
cat file.txtDisplay entire file contents
head -20 file.txtShow first 20 lines
tail -f log.txtFollow a file in real time (great for logs)
wc -l file.txtCount lines in a file
du -sh dir/Show directory size (human-readable)
df -hShow disk space usage
tree -L 2Display directory tree (2 levels)
stat file.txtShow detailed file metadata
file file.txtDetect file type
⚠️ Warning: rm -rf is irreversible. Always double-check the path before running it. A misplaced space like rm -rf / tmp/ will delete your entire filesystem.

2. Text Processing & Search

Linux excels at text processing. These commands let you search, filter, transform, and analyze text files efficiently.

CommandDescription
grep "pattern" fileSearch for a pattern in a file
grep -r "error" /var/logRecursively search directories
grep -i "warning"Case-insensitive search
grep -n "TODO" *.pySearch with line numbers
sed 's/old/new/g' fileFind and replace text
sed -i 's/foo/bar/g' fileFind and replace in-place
awk '{print $1}' filePrint first column
awk -F, '{print $2}' csvPrint second field (comma-separated)
sort file.txtSort lines alphabetically
sort -n file.txtSort numerically
sort -k2 -n file.txtSort by second column
uniqRemove duplicate consecutive lines
sort file | uniq -cCount unique occurrences
cut -d: -f1 /etc/passwdExtract first field (colon-delimited)
tr 'a-z' 'A-Z'Convert lowercase to uppercase
diff file1 file2Compare two files
tee output.txtRead from stdin, write to stdout and file
xargs commandBuild arguments from stdin

Pipeline Examples

# Find the 10 largest files
du -ah / | sort -rh | head -10

# Count HTTP status codes from access log
awk '{print $9}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head

# Find all Python files modified in the last 7 days
find . -name "*.py" -mtime -7

# Search and replace across all HTML files
find . -name "*.html" -exec sed -i 's/http:/https:/g' {} \;

3. File Permissions & Ownership

Linux uses a permission system based on read (r), write (w), and execute (x) for three categories: owner, group, and others.

CommandDescription
chmod 755 fileSet rwxr-xr-x permissions
chmod +x script.shMake a script executable
chmod 600 secret.keyOwner read/write only (secure files)
chown user:group fileChange file owner and group
chown -R user:group dir/Recursively change ownership
chgrp group fileChange group ownership
umask 022Set default permission mask
getfacl fileView ACL permissions
setfacl -m u:alice:rw fileSet ACL for specific user

Permission Numbers Quick Reference

NumberBinaryPermission
7111rwx (read, write, execute)
6110rw- (read, write)
5101r-x (read, execute)
4100r-- (read only)
0000--- (no permissions)

4. Process Management

Monitor and control running processes on your Linux system.

CommandDescription
ps auxList all running processes
ps aux | grep nginxFind specific process
topInteractive process monitor
htopBetter interactive process monitor
kill PIDTerminate a process (SIGTERM)
kill -9 PIDForce kill a process (SIGKILL)
pkill -f "process"Kill processes by name
killall nginxKill all processes by name
bg / fgResume process in background / foreground
nohup cmd &Run command immune to hangups
jobsList background jobs
lsof -i :8080Find process using port 8080
pgrep -a pythonFind process IDs by name
💡 Tip: Use Ctrl+Z to suspend a running process, then bg to send it to background, or fg to bring it back to foreground.

5. Disk & Storage

CommandDescription
df -hDisk space (human-readable)
df -iInode usage
du -sh *Size of each item in current directory
du -sh /var/logSize of a specific directory
lsblkList block devices
fdisk -lList disk partitions
mount /dev/sdb1 /mntMount a filesystem
umount /mntUnmount a filesystem
ncdu /Interactive disk usage analyzer

6. Networking Commands

Essential commands for debugging network issues, checking connectivity, and managing network interfaces. See also our curl cheat sheet for HTTP-specific commands.

CommandDescription
ping google.comTest network connectivity
ping -c 4 google.comSend exactly 4 packets
curl ifconfig.meGet your public IP address
ip addr showShow all network interfaces
ip routeShow routing table
netstat -tlnpShow listening TCP ports
ss -tlnpModern alternative to netstat
nslookup example.comDNS lookup
dig example.comDetailed DNS query
traceroute example.comTrace packet route to host
wget https://example.com/fileDownload a file
scp file.txt user@host:/pathCopy file over SSH
rsync -avz src/ dst/Efficiently sync directories
nmap -sP 192.168.1.0/24Scan local network for hosts
curl -I https://example.comGet HTTP headers

7. System Information

CommandDescription
uname -aSystem information (kernel, hostname, etc.)
cat /etc/os-releaseOS distribution details
hostnameShow hostname
uptimeSystem uptime and load averages
free -hMemory usage (human-readable)
nprocNumber of CPU cores
lscpuDetailed CPU information
lspciList PCI devices
lsusbList USB devices
dateShow current date and time
timedatectlManage system time and timezone
dmesg | tail -20Recent kernel messages
systemctl status nginxCheck service status
journalctl -u nginx -fFollow service logs

Need to convert timestamps between formats? Use our Timestamp Converter.

8. User Management

CommandDescription
whoamiCurrent username
idCurrent user ID and groups
useradd -m aliceCreate a new user with home directory
passwd aliceSet password for a user
userdel -r aliceDelete user and home directory
usermod -aG docker aliceAdd user to a group
groups aliceShow groups for a user
su - aliceSwitch to another user
sudo commandRun command as superuser

9. SSH & Remote Access

Secure Shell is the most common way to access remote Linux servers. See our Docker guide for container-related SSH tips.

CommandDescription
ssh user@hostConnect to remote server
ssh -p 2222 user@hostConnect on custom port
ssh-copy-id user@hostCopy SSH key to remote server
ssh-keygen -t ed25519Generate SSH key pair
ssh -L 8080:localhost:80 hostLocal port forwarding (tunnel)
ssh -R 3000:localhost:80 hostRemote port forwarding
scp file user@host:/pathSecure copy file to remote
scp -r dir/ user@host:/pathSecure copy directory recursively
sftp user@hostInteractive SFTP session

10. Package Management

Debian/Ubuntu (apt)

sudo apt update                  # Update package lists
sudo apt install package         # Install a package
sudo apt remove package          # Remove a package
sudo apt upgrade                 # Upgrade all packages
apt search "keyword"             # Search for packages
apt show package                 # Show package details

CentOS/RHEL/Fedora (dnf)

sudo dnf install package        # Install a package
sudo dnf remove package         # Remove a package
sudo dnf update                 # Update all packages
dnf search "keyword"            # Search for packages

Arch Linux (pacman)

sudo pacman -S package          # Install a package
sudo pacman -R package          # Remove a package
sudo pacman -Syu                # Update all packages
pacman -Ss "keyword"            # Search for packages

11. Archiving & Compression

CommandDescription
tar -czf archive.tar.gz dir/Create compressed tarball
tar -xzf archive.tar.gzExtract compressed tarball
tar -cjf archive.tar.bz2 dir/Create bz2 compressed tarball
zip archive.zip file1 file2Create a zip archive
unzip archive.zipExtract zip archive
gzip file.txtCompress a file
gunzip file.txt.gzDecompress a gz file
tar -tzf archive.tar.gzList contents of tarball

12. Pro Tips & Tricks

Bash Shortcuts

ShortcutAction
Ctrl + CInterrupt running command
Ctrl + ZSuspend current process
Ctrl + DExit shell / send EOF
Ctrl + LClear terminal screen
Ctrl + RReverse search command history
Ctrl + AMove cursor to start of line
Ctrl + EMove cursor to end of line
Ctrl + WDelete word before cursor
Alt + .Insert last argument of previous command
!!Repeat last command

Useful One-Liners

# Generate a secure random password
openssl rand -base64 32
# Or use our online tool: https://hedpy.cn/tools/password-generator

# Create a quick backup
cp important.conf important.conf.bak.$(date +%F)

# Find and delete empty files
find . -type f -empty -delete

# Monitor network connections in real time
watch -n 1 'ss -tlnp'

# Download all images from a page
curl -s https://example.com | grep -o 'src="[^"]*"' | grep -o 'http[^"]*' | xargs -n1 curl -O

# Batch rename files (add .bak extension)
for f in *.conf; do mv "$f" "$f.bak"; done
💡 Pro Tip: Set up shell aliases for commands you use frequently. Add them to ~/.bashrc or ~/.zshrc:
alias ll='ls -lah'
alias gs='git status'
alias gp='git push'
alias dc='docker compose'
alias ..='cd ..'
alias ...='cd ../..'

Conclusion

Mastering these Linux commands will dramatically improve your productivity as a developer, sysadmin, or DevOps engineer. Start with the basics — file navigation, grep, and permissions — then gradually learn the more advanced commands. Bookmark this page as your go-to reference, and check out our Docker commands guide and Git commands guide for more specialized cheat sheets.

🛠️ 推荐工具

免费在线开发工具,浏览器直接使用

前往工具站 → nbsp; AI API接口 →