___________ __________ _____ ________ ________ .____ ___________ \_ _____/ \______ \ / _ \ / _____/ / _____/ | | \_ _____/ | __) | _/ / /_\ \ / \ ___ / \ ___ | | | __)_ | \ | | \ / | \ \ \_\ \ \ \_\ \ | |___ | \ \___ / |____|_ / \____|__ / \______ / \______ / |_______ \ /_______ / \/ \/ \/ \/ \/ \/ \/

linux terminal commands Cheatsheet

← Back to cheatsheets

← Home


Essential Linux terminal commands and shell shortcuts.


File and Directory Operations

  • ls - List files
  • ls -l - List files (long format)
  • ls -a - List all files (including hidden)
  • ls -lah - List all files with details
  • cd <dir> - Change directory
  • cd .. - Go to parent directory
  • cd ~ - Go to home directory
  • cd - - Go to previous directory
  • pwd - Print working directory
  • mkdir <dir> - Create directory
  • mkdir -p <dir> - Create directory (with parents)
  • rmdir <dir> - Remove empty directory
  • rm <file> - Remove file
  • rm -r <dir> - Remove directory recursively
  • rm -rf <dir> - Remove directory (force)
  • cp <source> <dest> - Copy file
  • cp -r <source> <dest> - Copy directory
  • mv <source> <dest> - Move or rename file
  • touch <file> - Create empty file or update timestamp

File Permissions and Ownership

  • chmod <mode> <file> - Change file permissions
  • chmod +x <file> - Make file executable
  • chmod 755 <file> - Set permissions (rwxr-xr-x)
  • chmod 644 <file> - Set permissions (rw-r--r--)
  • chown <user>:<group> <file> - Change ownership
  • chown -R <user>:<group> <dir> - Change ownership recursively
  • sudo <command> - Execute command as root
  • sudo su - - Switch to root user

User and Group Management

User Commands

  • useradd <user> - Create new user
  • useradd -m <user> - Create user with home directory
  • useradd -G <group> <user> - Create user with additional group
  • usermod -aG <group> <user> - Add user to group
  • usermod -L <user> - Lock user account
  • usermod -U <user> - Unlock user account
  • userdel <user> - Delete user
  • userdel -r <user> - Delete user and home directory
  • passwd <user> - Change password for user
  • passwd - Change your own password
  • passwd -l <user> - Lock password (prevent login)
  • passwd -u <user> - Unlock password
  • passwd -e <user> - Force password expiration
  • chage -l <user> - List password aging info
  • id <user> - Show user ID and groups
  • whoami - Show current username
  • who - Show logged in users
  • w - Show logged in users and what they're doing

Group Commands

  • groupadd <group> - Create new group
  • groupdel <group> - Delete group
  • groupmod -n <newname> <oldname> - Rename group
  • groups - Show groups for current user
  • groups <user> - Show groups for user
  • gpasswd -a <user> <group> - Add user to group
  • gpasswd -d <user> <group> - Remove user from group
  • getent group <group> - Show group information

Sudo Commands

  • sudo -u <user> <command> - Run command as another user
  • sudo -s - Start shell as root
  • sudo su - <user> - Switch to another user
  • visudo - Edit sudoers file safely

Text Processing

  • cat <file> - Display file contents
  • less <file> - View file (scrollable)
  • more <file> - View file (page by page)
  • head <file> - Show first lines
  • tail <file> - Show last lines
  • tail -f <file> - Follow file (watch updates)
  • grep <pattern> <file> - Search for pattern
  • grep -r <pattern> <dir> - Search recursively
  • grep -i <pattern> <file> - Case insensitive search
  • sed 's/old/new/g' <file> - Replace text
  • awk '{print $1}' <file> - Print first column
  • wc <file> - Count lines, words, characters
  • wc -l <file> - Count lines
  • sort <file> - Sort lines
  • uniq <file> - Remove duplicate lines
  • cut -d: -f1 <file> - Cut by delimiter

Process Management

  • ps - List processes
  • ps aux - List all processes
  • top - Show running processes (interactive)
  • htop - Enhanced process viewer
  • kill <pid> - Kill process
  • kill -9 <pid> - Force kill process
  • killall <name> - Kill all processes by name
  • pkill <name> - Kill processes by name
  • jobs - List background jobs
  • fg - Bring job to foreground
  • bg - Send job to background
  • nohup <command> - Run command immune to hangups

System Information

  • df - Show disk space
  • df -h - Show disk space (human readable)
  • du - Show directory size
  • du -h - Show directory size (human readable)
  • free - Show memory usage
  • free -h - Show memory usage (human readable)
  • uname -a - Show system information
  • uptime - Show uptime
  • whoami - Show current user
  • id - Show user and group IDs
  • hostname - Show hostname
  • date - Show date and time

Archiving and Compression

  • tar -cf <archive.tar> <files> - Create tar archive
  • tar -xf <archive.tar> - Extract tar archive
  • tar -czf <archive.tar.gz> <files> - Create gzipped tar
  • tar -xzf <archive.tar.gz> - Extract gzipped tar
  • gzip <file> - Compress file
  • gunzip <file.gz> - Decompress file
  • zip <archive.zip> <files> - Create zip archive
  • unzip <archive.zip> - Extract zip archive

Network Operations

  • ping <host> - Ping host
  • wget <url> - Download file
  • curl <url> - Download file or fetch URL
  • ssh <user>@<host> - Connect via SSH
  • scp <file> <user>@<host>:<path> - Copy file via SSH
  • rsync -av <source> <dest> - Sync files
  • netstat - Show network connections
  • ifconfig - Show network interfaces
  • ip addr - Show IP addresses

Shell Shortcuts

  • Ctrl+A - Move to beginning of line
  • Ctrl+E - Move to end of line
  • Ctrl+U - Delete from cursor to beginning of line
  • Ctrl+K - Delete from cursor to end of line
  • Ctrl+W - Delete word before cursor
  • Ctrl+R - Reverse search history
  • Ctrl+C - Cancel/terminate command
  • Ctrl+D - Exit shell or delete character
  • Ctrl+L - Clear screen
  • Ctrl+Z - Suspend process
  • Alt+F - Move forward one word
  • Alt+B - Move backward one word
  • !! - Repeat last command
  • !<n> - Repeat command number n from history
  • !<string> - Repeat last command starting with string

Redirection and Pipes

  • <command> > <file> - Redirect output to file (overwrite)
  • <command> >> <file> - Redirect output to file (append)
  • <command> < <file> - Redirect input from file
  • <command> 2> <file> - Redirect stderr to file
  • <command> | <command> - Pipe output to another command
  • <command> & - Run command in background
  • <command1> && <command2> - Run command2 if command1 succeeds
  • <command1> || <command2> - Run command2 if command1 fails

Configuration

Config File Locations

  • ~/.bashrc - Bash configuration
  • ~/.zshrc - Zsh configuration
  • ~/.config/fish/config.fish - Fish shell configuration
  • ~/.profile - Shell profile (all shells)
  • ~/.bash_profile - Bash profile

Example Aliases

Add to your shell config:

# File operations
alias ll='ls -lah'
alias la='ls -A'
alias l='ls -CF'
alias ..='cd ..'
alias ...='cd ../..'

# Git shortcuts
alias gs='git status'
alias ga='git add'
alias gc='git commit'
alias gp='git push'
alias gl='git pull'

# System
alias df='df -h'
alias du='du -h'
alias free='free -h'

# Editor
export EDITOR=nvim
export VISUAL=nvim

Tips

  • Use tab completion for file names and commands
  • Use man <command> for help pages
  • Use <command> --help for command help
  • Use history to see command history
  • Use pipes to chain commands together
  • Use wildcards (*, ?) for pattern matching
  • Use quotes for strings with spaces
  • Use backticks or $() for command substitution
  • Use && and || for conditional execution
  • Use aliases for frequently used commands

← Back to cheatsheets

← Home