Welcome to the ultimate Linux commands cheat sheet, designed for beginners and seasoned sysadmins alike. This comprehensive guide covers 100 of the most essential Linux commands, organized by category, with clear descriptions, practical examples, and tips for chaining commands to streamline your workflows. Whether you’re managing files, monitoring systems, or scripting automation, this cheat sheet from SquidHacker is your go-to resource for mastering the Linux terminal.
File and Directory Management
Commands for creating, moving, copying, and deleting files and directories, plus tools for searching and archiving.
Text Processing
Tools for viewing, editing, searching, and manipulating text files, ideal for log analysis and data parsing.
System Information
Commands to monitor system resources, check hardware details, and track running processes.
Network
Utilities for managing network connections, testing connectivity, and transferring files securely.
User and Permission Management
Commands to create, modify, and delete user accounts, as well as manage file permissions.
Package Management
Tools for installing, updating, and managing software packages across different Linux distributions.
Process Management
Commands to monitor, prioritize, and terminate processes for efficient system performance.
Disk and Filesystem
Utilities for managing disks, partitions, and filesystems, including mounting and formatting.
Shell and Scripting
Commands for scripting, environment management, and creating shortcuts to streamline workflows.
Other Utilities
Miscellaneous tools for accessing manuals, clearing the terminal, and monitoring changes.
Introduction to Command Chaining
Chaining commands in Linux is a powerful way to combine multiple operations for efficient, automated workflows. By linking commands, you can process data, handle errors, and execute complex tasks in a single line. Here are the key methods:
Piping (|
) : Passes the output of one command as input to another.Example : ls -l | grep "txt"
lists files and filters those containing “txt”.
Redirection (>
, >>
, <
) : Redirects input/output to/from files.
>
: Overwrites a file with output. Example : echo "Hello" > hello.txt
.
>>
: Appends output to a file. Example : echo "World" >> hello.txt
.
<
: Reads input from a file. Example : sort < unsorted.txt
.
Logical Operators (&&
, ||
) :
&&
: Runs the second command if the first succeeds. Example : mkdir newdir && cd newdir
.
||
: Runs the second command if the first fails. Example : ping -c 1 google.com || echo "No internet"
.
Commands by Category
1. File and Directory Management
Command Description Purpose Basic Example Chaining Example ls
Lists directory contents View files and folders ls -l
ls -l | grep "txt"
(filters files by pattern)cd
Changes current directory Navigate filesystem cd /home/user
cd /tmp && touch temp.txt
(changes directory and creates file)pwd
Prints working directory Confirm current location pwd
pwd | xargs echo "Current dir:"
(displays with prefix)mkdir
Creates new directory Organize files mkdir newfolder
mkdir logs && cd logs
(creates and enters directory)rmdir
Removes empty directory Clean up unused folders rmdir oldfolder
rmdir oldfolder || echo "Directory not empty"
(handles errors)touch
Creates empty file or updates timestamp Initialize files touch file.txt
touch file.txt && echo "Data" > file.txt
(creates and writes to file)cp
Copies files/directories Duplicate data cp file.txt copy.txt
cp file.txt backup/ | xargs ls
(copies and lists)mv
Moves/renames files Relocate or rename mv file.txt newfile.txt
mv file.txt /tmp && ls /tmp
(moves and verifies)rm
Deletes files/directories Remove unwanted data rm -r folder
rm file.txt || echo "File not found"
(handles errors)find
Searches for files Locate specific files find /home -name "*.txt"
find . -type f -exec grep "error" {} \;
(searches text in files)locate
Finds files using database Quick file search locate document.pdf
locate *.pdf | xargs ls
(lists found PDFs)du
Estimates file space usage Check disk usage du -sh folder
du -sh * | sort -h
(sorts directories by size)df
Reports disk space usage Monitor free space df -h
df -h | grep "/dev/sda"
(filters specific disk)tar
Archives files Bundle files tar -cvf archive.tar folder
tar -cvf archive.tar folder | xargs ls -l
(archives and lists)gzip
Compresses files Reduce file size gzip file.txt
gzip file.txt && ls *.gz
(compresses and lists)gunzip
Decompresses files Restore compressed files gunzip file.txt.gz
gunzip file.txt.gz && cat file.txt
(decompresses and displays)zip
Compresses files into zip Create zip archives zip archive.zip file.txt
zip archive.zip *.txt | xargs ls
(zips and lists)unzip
Extracts zip files Access zipped content unzip archive.zip
unzip archive.zip && ls
(extracts and lists)ln
Creates links Share files via links ln -s file.txt link
ln -s file.txt link && ls -l
(creates link and verifies)file
Determines file type Identify file formats file document.pdf
file * | grep "PDF"
(filters PDF files)
2. Text Processing
Command Description Purpose Basic Example Chaining Example cat
Displays file contents View or concatenate files cat file.txt
cat file.txt | grep "error"
(filters lines)less
Views file content page-wise Read large files less log.txt
less log.txt | grep "error"
(searches while viewing)more
Displays file content page-wise Similar to less more log.txt
more log.txt | head -n 10
(shows first 10 lines)head
Shows first lines of file Preview file start head -n 5 file.txt
head file.txt | grep "start"
(filters first lines)tail
Shows last lines of file Monitor file end tail -n 5 file.txt
tail -f log.txt | grep "error"
(monitors errors)grep
Searches text patterns Find specific text grep "error" log.txt
ps aux | grep "process_name"
(finds processes)sed
Stream editor for text Modify text sed 's/old/new/' file.txt
cat file.txt | sed 's/error/warning/'
(replaces text)awk
Processes text patterns Extract data awk '{print $1}' file.txt
ps aux | awk '{print $2}'
(lists PIDs)sort
Sorts lines Organize data sort file.txt
cat file.txt | sort -u
(sorts uniquely)uniq
Filters repeated lines Remove duplicates uniq file.txt
sort file.txt | uniq
(removes duplicates)cut
Extracts sections from lines Parse delimited data cut -d',' -f1 file.csv
cat file.csv | cut -d',' -f1
(extracts first column)paste
Merges lines of files Combine data paste file1.txt file2.txt
paste file1.txt file2.txt | sort
(merges and sorts)wc
Counts lines, words, characters Analyze text wc -l file.txt
cat file.txt | wc -w
(counts words)tr
Translates characters Modify text tr 'a-z' 'A-Z' < file.txt
cat file.txt | tr '[:lower:]' '[:upper:]'
(converts case)tee
Writes to file and stdout Save and display output ls | tee output.txt
ls -l | tee output.txt | grep "txt"
(saves and filters)
3. System Information
Command Description Purpose Basic Example Chaining Example uname
Shows system information Check OS details uname -a
uname -r | xargs echo "Kernel:"
(displays kernel)hostname
Displays/sets hostname Identify system hostname
hostname | xargs echo "Host:"
(prefixes hostname)uptime
Shows system uptime Monitor runtime uptime
uptime | cut -d',' -f1
(extracts uptime)whoami
Shows current user Verify identity whoami
whoami | xargs echo "User:"
(prefixes user)id
Shows user/group IDs Check permissions id
id | grep "uid"
(filters UID)lscpu
Displays CPU info Check processor details lscpu
lscpu | grep "Model name"
(shows CPU model)lsblk
Lists block devices View disk layout lsblk
lsblk | grep "disk"
(filters disks)free
Shows memory usage Monitor RAM free -h
free -h | grep "Mem"
(shows memory line)top
Monitors processes View system activity top
top -bn1 | grep "load average"
(shows load)htop
Interactive process viewer Manage processes htop
htop -u user | grep "process"
(filters user processes)ps
Lists processes Check running tasks ps aux
ps aux | grep "httpd"
(finds httpd processes)kill
Terminates processes Stop tasks kill 1234
ps aux | grep "process" | awk '{print $2}' | xargs kill
(kills process)
4. Network
Command Description Purpose Basic Example Chaining Example ping
Tests network connectivity Check host reachability ping -c 4 google.com
ping -c 1 google.com || echo "No connection"
(handles failure)ifconfig
Configures network interfaces View network settings ifconfig
ifconfig | grep "inet"
(shows IP addresses)ip
Manages network settings Modern network tool ip addr show
ip addr show | grep "inet"
(filters IPs)netstat
Shows network connections Monitor network netstat -tuln
netstat -tuln | grep ":80"
(filters port 80)ss
Investigates sockets View connections ss -tuln
ss -tuln | grep "80"
(filters port 80)traceroute
Traces packet routes Diagnose network paths traceroute google.com
traceroute google.com | tail -n 5
(shows last hops)nslookup
Queries DNS servers Resolve domains nslookup google.com
nslookup google.com | grep "Address"
(shows IPs)dig
Performs DNS lookups Detailed DNS info dig google.com
dig google.com | grep "ANSWER"
(shows answers)wget
Downloads files Fetch web content wget http://example.com/file
wget -qO- http://example.com | grep "title"
(fetches and searches)curl
Transfers data API/web requests curl http://example.com
curl -s http://example.com | grep "html"
(fetches silently)scp
Securely copies files Transfer between hosts scp file.txt user@host:/path
scp file.txt user@host:/path && ssh user@host ls
(copies and lists)ssh
Connects to remote hosts Remote management ssh user@host
ssh user@host "ls -l" | grep "file"
( AscendingOrder:
5. User and Permission Management
Command Description Purpose Basic Example Chaining Example useradd
Creates new user Add accounts useradd -m john
useradd -m john && passwd john
(adds user and sets password)usermod
Modifies user account Update user settings usermod -aG sudo john
usermod -aG sudo john && groups john
(adds to group and verifies)userdel
Deletes user account Remove users userdel -r john
userdel -r john || echo "User not found"
(handles errors)passwd
Changes passwords Secure accounts passwd john
passwd john && echo "Password updated"
(confirms update)sudo
Runs commands as another user Execute with privileges sudo apt update
sudo apt update && sudo apt upgrade
(updates system)su
Switches user Change identity su - john
su - john -c "whoami" | grep "john"
(verifies user)chown
Changes file ownership Assign owners chown john file.txt
chown john file.txt && ls -l
(changes and verifies)chmod
Changes file permissions Set access rights chmod 755 file.txt
chmod 755 file.txt && ls -l
(sets and verifies)umask
Sets default permissions Control new file permissions umask 022
umask 022 && touch file.txt && ls -l
(sets and tests)
6. Package Management
Command Description Purpose Basic Example Chaining Example apt
Manages Debian packages Install/update software apt update
apt update && apt install nginx
(updates and installs)yum
Manages RPM packages Install software (CentOS) yum install httpd
yum update && yum install httpd
(updates and installs)dnf
Modern RPM package manager Install software (Fedora) dnf install vim
dnf update && dnf install vim
(updates and installs)pacman
Manages Arch packages Install software pacman -S vim
pacman -Syu && pacman -S vim
(updates and installs)dpkg
Installs Debian packages Manage .deb files dpkg -i package.deb
dpkg -i package.deb && apt install -f
(installs and fixes)
7. Process Management
Command Description Purpose Basic Example Chaining Example killall
Kills processes by name Stop multiple processes killall firefox
killall firefox || echo "No firefox running"
(handles errors)pkill
Kills processes by name Stop processes pkill -9 sshd
pkill sshd && echo "Processes killed"
(confirms kill)nice
Sets process priority Control resource usage nice -n 10 command
nice -n 10 sleep 10 && echo "Done"
(runs with priority)renice
Changes running process priority Adjust priority renice 10 1234
renice 10 1234 && ps -p 1234
(changes and verifies)bg
Runs job in background Manage jobs bg %1
jobs | grep "stopped" | xargs bg
(resumes stopped jobs)fg
Brings job to foreground Manage jobs fg %1
jobs | grep "running" | xargs fg
(brings to foreground)jobs
Lists active jobs Monitor jobs jobs
jobs | grep "running"
(filters running jobs)
8. Disk and Filesystem
Command Description Purpose Basic Example Chaining Example mount
Mounts filesystems Access disks mount /dev/sda1 /mnt
mount /dev/sda1 /mnt && ls /mnt
(mounts and lists)umount
Unmounts filesystems Detach disks umount /mnt
umount /mnt || echo "Unmount failed"
(handles errors)fdisk
Manages partitions Create partitions fdisk /dev/sda
fdisk -l | grep "/dev/sda"
(lists partitions)mkfs
Creates filesystems Format disks mkfs.ext4 /dev/sda1
mkfs.ext4 /dev/sda1 && mount /dev/sda1 /mnt
(formats and mounts)fsck
Checks/repairs filesystems Fix disk errors fsck /dev/sda1
fsck /dev/sda1 || echo "Errors found"
(handles errors)
9. Shell and Scripting
Command Description Purpose Basic Example Chaining Example echo
Prints text Display variables/messages echo "Hello"
echo $PATH | tr ':' '\n'
(splits PATH)printf
Formats text Precise output formatting printf "Value: %s\n" "test"
printf "%s\n" *.txt | sort
(lists and sorts files)alias
Creates command shortcuts Simplify commands alias ll='ls -l'
alias ll='ls -l' && ll
(sets and uses alias)history
Shows command history Review past commands history
history | grep "git"
(filters git commands)env
Shows environment variables Check settings env
env | grep "PATH"
(filters PATH)
10. Other Utilities
Command Description Purpose Basic Example Chaining Example man
Displays command manuals Learn command usage man ls
man ls | less
(paginates manual)whatis
Shows command description Quick command info whatis ls
whatis ls | grep "list"
(filters description)whereis
Locates command files Find binaries whereis ls
whereis ls | cut -d' ' -f2
(extracts path)clear
Clears terminal Clean screen clear
ls && clear
(lists then clears)watch
Runs command periodically Monitor changes watch -n 1 'date'
watch -n 1 'df -h' | grep "/dev/sda"
(monitors disk)
Notes
Distribution-Specific Commands : Commands like apt
(Debian/Ubuntu), yum
(CentOS), or pacman
(Arch) are specific to certain Linux distributions. Verify compatibility with your system.
Advanced Chaining : The chaining examples here are simplified. Combine multiple commands for more complex tasks as you gain experience.
Documentation : Always consult man
pages or online resources for detailed command options and advanced usage.
Safety First : Commands like rm
, kill
, or mkfs
can cause data loss or system issues if misused. Double-check before executing.
Why This Cheat Sheet Rocks
This cheat sheet isn’t just a list—it’s a roadmap to Linux mastery. Each command comes with practical examples and chaining ideas to help you work smarter, not harder. Bookmark this page, share it with your fellow hackers, and revisit it whenever you need to conquer the terminal. Stay curious, keep experimenting, and happy hacking!
Originally published on SquidHacker – Your source for Linux tips, cybersecurity, and tech tutorials.