Linux Commands Cheatsheet
Comprehensive guide to essential Linux commands covering file operations, system information, process management, networking, package management, text processing, and more. Your go-to reference for daily Linux terminal operations.
Free account required
Command Syntax
$ command [options] [arguments] Table of Contents
File Management
ls - List directory contents
$ ls -lah /path/to/directory Common options: -l (long format), -a (show hidden), -h (human readable)
cd - Change directory
$ cd /path/to/directory
$ cd ~ # Go to home directory
$ cd .. # Go up one directory
$ cd - # Go to previous directory pwd - Print working directory
$ pwd Shows the full path of current directory
mkdir - Make directories
$ mkdir dirname
$ mkdir -p /path/to/nested/dirs # Create parent directories rm - Remove files or directories
$ rm file.txt
$ rm -r directory/ # Remove directory recursively
$ rm -rf directory/ # Force remove without prompts cp - Copy files or directories
$ cp source.txt dest.txt
$ cp -r source_dir/ dest_dir/ # Copy directory recursively mv - Move or rename files
$ mv oldname.txt newname.txt # Rename
$ mv file.txt /path/to/dest/ # Move touch - Create empty file or update timestamp
$ touch newfile.txt ln - Create links
$ ln -s /path/to/file linkname # Create symbolic link
$ ln /path/to/file linkname # Create hard link File Viewing & Editing
cat - Concatenate and display files
$ cat file.txt
$ cat file1.txt file2.txt > combined.txt # Combine files less - View file contents (paginated)
$ less file.txt Use arrows to navigate, q to quit, / to search
more - View file contents (simple pager)
$ more file.txt head - Display first lines of file
$ head file.txt # First 10 lines
$ head -n 20 file.txt # First 20 lines tail - Display last lines of file
$ tail file.txt # Last 10 lines
$ tail -n 20 file.txt # Last 20 lines
$ tail -f log.txt # Follow file updates (real-time) nano - Simple text editor
$ nano file.txt Use Ctrl+X to exit, Ctrl+O to save
vim - Advanced text editor
$ vim file.txt Press i to insert, Esc then :wq to save and quit
System Information
uname - System information
$ uname -a # All information
$ uname -r # Kernel version whoami - Current username
$ whoami hostname - Show or set system hostname
$ hostname
$ hostname -I # Show IP addresses uptime - System uptime
$ uptime Shows how long system has been running and load averages
date - Display or set date and time
$ date
$ date +"%Y-%m-%d %H:%M:%S" # Custom format df - Disk space usage
$ df -h # Human readable format du - Directory space usage
$ du -sh directory/ # Summary
$ du -h --max-depth=1 # One level deep free - Memory usage
$ free -h # Human readable lscpu - CPU information
$ lscpu Process Management
ps - Process status
$ ps aux # All processes
$ ps aux | grep nginx # Find specific process top - Real-time process monitor
$ top Press q to quit
htop - Interactive process viewer
$ htop More user-friendly than top (requires installation)
kill - Terminate process by PID
$ kill 1234 # Graceful termination
$ kill -9 1234 # Force kill killall - Kill processes by name
$ killall nginx jobs - List background jobs
$ jobs bg - Resume suspended job in background
$ bg %1 # Resume job 1 fg - Bring job to foreground
$ fg %1 # Bring job 1 to foreground nice - Run command with modified priority
$ nice -n 10 command # Lower priority User Management
useradd - Create new user
$ sudo useradd username
$ sudo useradd -m -s /bin/bash username # Create with home dir userdel - Delete user
$ sudo userdel username
$ sudo userdel -r username # Remove home directory too usermod - Modify user account
$ sudo usermod -aG sudo username # Add to group passwd - Change user password
$ passwd # Change your password
$ sudo passwd username # Change another user's password su - Switch user
$ su username # Switch to user
$ su - # Switch to root with environment sudo - Execute command as superuser
$ sudo command
$ sudo -i # Start root shell who - Show logged in users
$ who w - Show who is logged in and what they're doing
$ w Network Commands
ping - Test network connectivity
$ ping google.com
$ ping -c 4 google.com # Send only 4 packets netstat - Network statistics (legacy)
$ netstat -tuln # Show listening ports ss - Socket statistics (modern alternative to netstat)
$ ss -tuln # Show listening ports ifconfig - Network interface configuration (legacy)
$ ifconfig ip - Network configuration (modern)
$ ip addr show # Show IP addresses
$ ip route # Show routing table See our IP Command Cheatsheet for detailed reference
curl - Transfer data from/to servers
$ curl https://example.com
$ curl -O https://example.com/file.zip # Download See our Curl Cheatsheet for comprehensive examples
wget - Download files from web
$ wget https://example.com/file.zip
$ wget -c https://example.com/file.zip # Resume download ssh - Secure shell remote login
$ ssh user@hostname
$ ssh -p 2222 user@hostname # Custom port scp - Secure copy over SSH
$ scp file.txt user@hostname:/path/
$ scp user@hostname:/path/file.txt ./ # Download Package Management
Package manager varies by Linux distribution. Use the appropriate commands for your system.
Debian/Ubuntu (apt/apt-get)
Update package list
$ sudo apt update Upgrade packages
$ sudo apt upgrade
$ sudo apt full-upgrade # Also handles dependencies Install package
$ sudo apt install package-name Remove package
$ sudo apt remove package-name
$ sudo apt purge package-name # Also remove config files RHEL/CentOS/Fedora (yum/dnf)
Update package list
$ sudo yum check-update
$ sudo dnf check-update # Fedora Install package
$ sudo yum install package-name
$ sudo dnf install package-name # Fedora Remove package
$ sudo yum remove package-name
$ sudo dnf remove package-name # Fedora Arch Linux (pacman)
Update and upgrade
$ sudo pacman -Syu Install package
$ sudo pacman -S package-name Remove package
$ sudo pacman -R package-name Archiving & Compression
tar - Archive files
$ tar -czf archive.tar.gz directory/ # Create gzipped archive
$ tar -xzf archive.tar.gz # Extract gzipped archive
$ tar -cjf archive.tar.bz2 directory/ # Create bzip2 archive
$ tar -xjf archive.tar.bz2 # Extract bzip2 archive
$ tar -tf archive.tar.gz # List contents Options: c=create, x=extract, z=gzip, j=bzip2, f=file, v=verbose
gzip - Compress files
$ gzip file.txt # Compress (creates file.txt.gz)
$ gzip -d file.txt.gz # Decompress gunzip - Decompress gzip files
$ gunzip file.txt.gz zip - Create ZIP archives
$ zip archive.zip file1 file2
$ zip -r archive.zip directory/ # Recursive unzip - Extract ZIP archives
$ unzip archive.zip
$ unzip -l archive.zip # List contents bzip2 - Compress with bzip2
$ bzip2 file.txt # Compress
$ bzip2 -d file.txt.bz2 # Decompress Searching
find - Search for files
$ find /path -name"*.txt" # Find by name
$ find /path -type f -mtime -7 # Modified in last 7 days
$ find /path -type d # Find directories only
$ find /path -size +100M # Files larger than 100MB grep - Search text patterns
$ grep"pattern" file.txt
$ grep -r"pattern" /path/ # Recursive search
$ grep -i"pattern" file.txt # Case insensitive
$ grep -n"pattern" file.txt # Show line numbers
$ grep -v"pattern" file.txt # Invert match locate - Find files by name (fast)
$ locate filename
$ sudo updatedb # Update locate database which - Locate a command
$ which python
$ which -a python # Show all matches whereis - Locate binary, source, and manual
$ whereis python Text Processing
awk - Pattern scanning and processing
$ awk'{print $1}' file.txt # Print first column
$ awk -F:'{print $1}' /etc/passwd # Custom delimiter sed - Stream editor
$ sed's/old/new/' file.txt # Replace first occurrence
$ sed's/old/new/g' file.txt # Replace all occurrences
$ sed -i's/old/new/g' file.txt # Edit file in-place cut - Cut out sections of lines
$ cut -d: -f1 /etc/passwd # Cut by delimiter
$ cut -c1-10 file.txt # Cut by character position sort - Sort lines
$ sort file.txt
$ sort -r file.txt # Reverse sort
$ sort -n file.txt # Numeric sort uniq - Remove duplicate lines
$ sort file.txt | uniq
$ sort file.txt | uniq -c # Count occurrences wc - Word count
$ wc file.txt # Lines, words, bytes
$ wc -l file.txt # Count lines
$ wc -w file.txt # Count words tr - Translate or delete characters
$ echo"hello" | tr'a-z''A-Z' # Uppercase
$ tr -d'' < file.txt # Delete spaces Permissions
chmod - Change file permissions
$ chmod 755 file.txt
$ chmod u+x script.sh # Add execute for user
$ chmod -R 644 directory/ # Recursive chown - Change file owner
$ sudo chown user file.txt
$ sudo chown user:group file.txt
$ sudo chown -R user:group directory/ chgrp - Change group ownership
$ sudo chgrp group file.txt Master Linux on Powerful VPS Hosting
Ready to put your Linux skills to work? Explore our curated VPS providers, find the perfect hosting with our comprehensive benchmarks, and compare performance to choose the best infrastructure for your Linux workloads.