We created this Linux Commands Cheat Sheet initially for students of our DevOps & Linux Bootcamp. But we're now sharing it with any and all DevOps Engineers, SysAdmins, and Developers that want to learn and remember some of the key Linux Commands and have a quick reference guide to the basics of Linux.
Enter your email below and we'll send it to you 👇
Send Me The PDFIf you’ve stumbled across this cheatsheet and are just starting to learn Linux, you've made a great choice!
Linux powers the internet. It’s everywhere. From the smallest to the biggest companies like Amazon, Microsoft, SpaceX. They’re all using Linux on their backend, so it's great to learn if you're interested in becoming a DevOps Engineer or SysAdmin.
However, if you're stuck in an endless cycle of YouTube tutorials and want to start building real world projects and actually get hired, then come join the Zero To Mastery Academy.
You'll learn Linux + devops from actual industry professionals alongside thousands of students in our private Discord community.
You'll not only learn to become a top 10% DevOps Engineer by learning advanced topics most courses don't cover, but you'll also build awesome projects that you can add to your portfolio and wow employers with!
Just want the cheatsheet? No problem! Please enjoy and if you'd like to submit any suggestions, feel free to email us at support@zerotomastery.io
The man pages are navigated using the less command with shortcuts:
TAB TAB: Display all commands or filenames starting with written letters. CTRL + L: Clear the current line. CTRL + D: Close the shell. CTRL + U: Cut the current line. CTRL + A: Move cursor to start of the line. Ctrl + E: Move cursor to the end of the line. CTRL + C: Stop the current command. CTRL + Z: Sleep the running program. CTRL + ALT + T: Open a terminal.
Usage: ls [OPTIONS] [FILES]
Copy files and directories:
Move or rename files and directories:
Remove files and directories:
Redirect output and errors:
Search with various options:
Usage: grep [OPTIONS] PATTERN FILE
## Account Management /etc/passwd # users and info: /etc/shadow # users' passwords /etc/group # groups ## User Commands useradd [OPTIONS] username # Create user. usermod [OPTIONS] username # Modify user. userdel -r username # Delete user. ## Group Commands groupadd group_name # Create group. groupdel group_name # Delete group. ## Examples useradd -m -d /home/john -c "C++ Developer" -s /bin/bash -G sudo,adm,mail john # Example of creating a user. usermod -aG developers,managers john # Example of modifying a user.
## Commands who -H # User info. id # User info. whoami # User info. w # System usage. uptime # System usage. last # Login history. last -u username # Login history for a specific user.
Ubuntu
sudo apt update && sudo apt install openssh-server openssh-client
CentOS
sudo dnf install openssh-server openssh-clients
ssh -p 22 username@server_ip # Connect using default SSH port ssh -p 22 -l username server_ip # Connect with a specific username ssh -v -p 22 username@server_ip # Connect in verbose mode for detailed information # Ubuntu sudo systemctl status ssh # Check SSH status sudo systemctl stop ssh # Stop SSH service sudo systemctl restart ssh # Restart SSH service sudo systemctl enable ssh # Enable SSH to start on boot sudo systemctl is-enabled ssh # Check if SSH is enabled on boot # CentOS sudo systemctl status sshd # Check SSH status sudo systemctl stop sshd # Stop SSH service sudo systemctl restart sshd # Restart SSH service sudo systemctl enable sshd # Enable SSH to start on boot sudo systemctl is-enabled sshd # Check if SSH is enabled on boot
Edit /etc/ssh/sshd_config and then apply changes by restarting SSH:
Remember to consult the man page ( man sshd_config ) for detailed configuration options.
# Copy local file to remote host scp a.txt john@80.0.0.1:~ scp -P 2288 a.txt john@80.0.0.1:~ # Custom port # Copy from remote to local scp -P 2290 john@80.0.0.1:~/a.txt . # Copy entire directory to remote scp -P 2290 -r projects/ john@80.0.0.1:~
# Sync local directory to local backup sudo rsync -av /etc/ ~/etc-backup/ # Mirror directory, deleting extraneous files from dest sudo rsync -av --delete /etc/ ~/etc-backup/ # Exclude files during sync rsync -av --exclude-from='~/exclude.txt' /source/ /dest/ # Sync over SSH with custom port sudo rsync -av -e 'ssh -p 2267' /etc/ student@192.168.0.108:~/etc-backup/
# exclude.txt could include patterns like: *.avi music/ abc.mkv # Exclude specific file types during transfer rsync -av --exclude='*.mkv' /source/ /dest/
# Install wget sudo apt install wget # Ubuntu sudo dnf install wget # CentOS # Basic file download wget https://example.com/file.iso # Resume incomplete download wget -c https://example.com/file.iso # Download with bandwidth limit wget --limit-rate=100k https://example.com/file.iso # Download multiple files wget -i urls.txt # urls.txt contains list of URLs # Recursive download for offline viewing of a website wget -mkEpnp http://example.org
Use these commands to efficiently copy files and directories across systems and for downloading content from the internet, ensuring data synchronization and maintaining web accessibility.
# Display all ports and connections sudo netstat -tupan sudo ss -tupan # Check if port 80 is open netstat -tupan | grep :80
# List open files lsof # Files opened by a specific user lsof -u username # Files opened by a specific command/process lsof -c sshd Open files for TCP ports in LISTEN state lsof -iTCP -sTCP:LISTEN lsof -iTCP -sTCP:LISTEN -nP
Use these commands to monitor network connections, check for open ports, and view files opened by users or processes, especially for security and troubleshooting.
# SYN Scan (root required) nmap -sS 192.168.0.1 # TCP Connect Scan nmap -sT 192.168.0.1 # Scan All Ports nmap -p- 192.168.0.1 # Scan Specific Ports nmap -p 20,22-100,443,1000-2000 192.168.0.1 # Service Version Detection nmap -p 22,80 -sV 192.168.0.1 # Ping Scan Network nmap -sP 192.168.0.0/24 # Skip Host Discovery nmap -Pn 192.168.0.0/24 # Exclude Specific IP from Scan nmap -sS 192.168.0.0/24 --exclude 192.168.0.10 # Output Scan to File nmap -oN output.txt 192.168.0.1 # OS Detection nmap -O 192.168.0.1 # Aggressive Scan nmap -A 192.168.0.1 # Read Targets from File & Output to File without DNS Resolution nmap -n -iL hosts.txt -p 80 -oN output.txt
Only scan your own networks and systems, or those you have explicit permission to test. Unauthorized scanning can be illegal.
crontab -e # Edit crontab crontab -l # List tasks crontab -r # Remove tasks # Schedule Format: * * * * * command # Every minute 15 * * * * command # Hourly 30 18 * * * command # Daily 3 22 * * 1 command # Weekly 10 6 1 * * command # Monthly @yearly command # Yearly @reboot command # At reboot
lshw # Full hardware info lshw -short # Short format lshw -json # JSON format lshw -html # HTML format
lscpu # CPU details lshw -C cpu # Hardware-specific CPU details lscpu -J # JSON format
dmidecode -t memory # RAM specs dmidecode -t memory | grep -i size dmidecode -t memory | grep -i max free -m # Memory usage
lspci # PCI buses and connected devices lspci | grep -i wireless lspci | grep -i vga lsusb # USB controllers and devices lsusb -v # Verbose output
lshw -short -C disk fdisk -l # List disks fdisk -l /dev/sda lsblk # Block devices list
lshw -C network iw list # Wi-Fi cards iwconfig # Wi-Fi configuration iwlist scan # Wi-Fi networks scan
cat /proc/cpuinfo # CPU info cat /proc/meminfo # Memory info cat /proc/version # System version uname -r # Kernel version uname -a # All system info
acpi -bi # Battery info acpi -V # All ACPI info
# Backup MBR dd if=/dev/sda of=~/mbr.dat bs=512 count=1 # Restore MBR dd if=~/mbr.dat of=/dev/sda bs=512 count=1 # Clone partition dd if=/dev/sda1 of=/dev/sdb2 bs=4M status=progress
Use these commands to check hardware specifications and perform operations with device files safely.
# Analyze boot process systemd-analyze systemd-analyze blame # List active units systemctl list-units systemctl list-units | grep ssh # Service status sudo systemctl status nginx.service # Stop service sudo systemctl stop nginx # Start service sudo systemctl start nginx # Restart service sudo systemctl restart nginx # Reload service config sudo systemctl reload nginx sudo systemctl reload-or-restart nginx # Enable service at boot sudo systemctl enable nginx # Disable service at boot sudo systemctl disable nginx # Check if service is enabled at boot sudo systemctl is-enabled nginx # Mask service sudo systemctl mask nginx # Unmask service sudo systemctl unmask nginx
sudo systemctl status ssh # Check SSH service status sudo systemctl stop ssh # Stop SSH service sudo systemctl restart ssh # Restart SSH service sudo systemctl enable ssh # Enable SSH to start on boot sudo systemctl is-enabled ssh # Check if SSH is enabled on boot
sudo systemctl status sshd # Check SSHD service status sudo systemctl stop sshd # Stop SSHD service sudo systemctl restart sshd # Restart SSHD service sudo systemctl enable sshd # Enable SSHD to start on boot sudo systemctl is-enabled sshd # Check if SSHD is enabled on boot
To configure security settings, edit /etc/ssh/sshd_config . Apply changes by restarting SSH. Key configurations include:
Note: Consult the man page ( man sshd_config ) for detailed configuration options.
alias # List all aliases alias name='command' # Create an alias unalias name # Remove an alias
alias c='clear' alias cl='clear; ls; pwd' alias root='sudo su' alias ports='netstat -tupan' alias sshconfig='sudo vim /etc/ssh/sshd_config' alias update='sudo apt update && sudo apt dist-upgrade -y && sudo apt clean'
alias cp='cp -i' alias mv='mv -i' alias rm='rm -i'
variable="value" # Define a variable echo $variable # Reference a variable declare -r const=100 # Define a read-only variable unset variable # Unset a variable env | grep PATH # Find an environment variable export PATH=$PATH:~/bin # Modify the PATH variable
$0, $1, $2, ..., $ # Script name & positional arguments $# # Number of positional arguments "$*" # All positional arguments as a single string $? # Exit status of the last command
if [ condition ]; then command; fi # Basic if statement if [ condition ]; then command; else other_command; fi # If-else statement if [ condition ]; then command; elif [ condition ]; then... # If-elif-else statement
# Numeric comparisons: -eq, -ne, -lt, -le, -gt, -ge # File checks: -s, -f, -d, -x, -w, -r # String comparisons: =, !=, -n (not zero), -z (is zero) # Logical operators: && (and), || (or)
for i in 1..5>; do echo "Loop $i"; done # For loop while [ condition ]; do command; done # While loop case "$variable" in pattern) command;; esac # Case statement function name() command; > # Function definition name() command; > # Alternative function syntax name # Call a function
crontab -e # Edit crontab file crontab -l # List crontab entries crontab -r # Remove crontab entries
Combine these constructs to write effective bash scripts for task automation and system management.