Skip to main content

Command Palette

Search for a command to run...

Linux cheatsheet

Updated
6 min read
Linux cheatsheet
A

Senior Backend Engineer

Here is an extended and fully annotated version of the Linux Cheatsheet blog in Markdown, with:

  • Brief descriptions for each command

  • An Advanced Topics section covering cron, systemd, firewalld, SELinux, and more


Linux Cheat sheet

System Information

CommandDescription
uname -aShow kernel version and system architecture
hostnameDisplay system hostname
uptimeShow how long the system has been running
whoamiShow the currently logged-in user
idDisplay user ID and group information
lsb_release -aDisplay Linux distribution info (Debian-based)
cat /etc/os-releaseShow OS information (universal method)

File and Directory Management

CommandDescription
ls -lList files with details
ls -aInclude hidden files
pwdShow current directory
cd /path/to/dirChange to target directory
mkdir newdirCreate a new directory
touch file.txtCreate an empty file
cp source destCopy file or directory
mv old newRename or move a file/directory
rm file.txtDelete a file
rm -r dirRecursively delete a directory and its contents

File Permissions

CommandDescription
chmod 755 fileSet permissions (owner: rwx, group/others: rx)
chown user:group fileChange file ownership
ls -l fileShow file permissions

Shorthand permission examples:

chmod u+x script.sh     # Add execute to user
chmod go-rw file.txt    # Remove read/write from group and others

User Management

CommandDescription
adduser arpitAdd new user
passwd arpitSet/change password for a user
deluser arpitDelete a user
usermod -aG sudo arpitAdd user to the sudo group
groupsShow current user's groups

Package Management

Debian/Ubuntu

sudo apt update               # Update package index
sudo apt upgrade              # Upgrade installed packages
sudo apt install <pkg>        # Install package
sudo apt remove <pkg>         # Remove package
sudo apt purge <pkg>          # Remove including config files

Amazon Linux / RHEL / CentOS

sudo yum update               # Update packages
sudo yum install <pkg>        # Install package
sudo yum remove <pkg>         # Remove package

Common Utility Installation

UtilityDescriptionDebian-basedRHEL-based
curlTransfer data from URLssudo apt install curlsudo yum install curl
dnsutilsDNS tools: dig, nslookupsudo apt install dnsutilssudo yum install bind-utils
gitVersion control systemsudo apt install gitsudo yum install git
htopInteractive process viewersudo apt install htopsudo yum install htop
iproute2Modern networking commandssudo apt install iproute2sudo yum install iproute
jqJSON processorsudo apt install jqsudo yum install jq
net-toolsLegacy networking commandssudo apt install net-toolssudo yum install net-tools
netcatTCP/UDP networking toolsudo apt install netcatsudo yum install nc
nmapNetwork scannersudo apt install nmapsudo yum install nmap
python3Python interpretersudo apt install python3sudo yum install python3
pip3Python package managersudo apt install python3-pipsudo yum install python3-pip
screenTerminal multiplexersudo apt install screensudo yum install screen
telnetTest TCP connectivitysudo apt install telnetsudo yum install telnet
tmuxTerminal multiplexersudo apt install tmuxsudo yum install tmux
treeShow directory treesudo apt install treesudo yum install tree
unzipExtract .zip filessudo apt install unzipsudo yum install unzip
wgetDownload files from websudo apt install wgetsudo yum install wget
zipCompress files into .zipsudo apt install zipsudo yum install zip

Process Management

CommandDescription
ps auxList all processes
topReal-time view of processes
htopEnhanced interactive process viewer
kill PIDTerminate a process by PID
kill -9 PIDForce kill a process
pkill nameKill processes by name
jobsList background jobs
bgResume a job in the background
fgBring background job to foreground

Networking

CommandDescription
ip aShow IP addresses
ip rShow routing table
ping hostPing a host
traceroute hostTrace route to a host
netstat -tulnpShow listening ports
ss -tulnShow socket status
curl ifconfig.meShow public IP address
host domain.comDNS lookup
dig domain.comDetailed DNS info

Disk Usage

CommandDescription
df -hShow free space on mounted filesystems
du -sh *Show size of directories/files in current dir
lsblkShow block devices (disks, partitions)
mountShow mounted file systems

Searching and Grep

CommandDescription
find . -name "*.log"Find files by name pattern
grep "pattern" file.txtSearch for a pattern in a file
grep -r "pattern" /dirRecursive search
locate filenameQuickly find files (needs updatedb)
updatedbUpdate locate database

Compression and Archiving

CommandDescription
tar -cvf archive.tar dir/Create a tar archive
tar -xvf archive.tarExtract tar archive
tar -czvf archive.tar.gz dir/Create a compressed tar.gz
tar -xzvf archive.tar.gzExtract tar.gz
zip archive.zip fileCreate a zip archive
unzip archive.zipExtract a zip archive

System Monitoring

CommandDescription
uptimeShow system load and uptime
free -hShow memory usage
vmstatSystem performance metrics
iostatCPU and I/O usage (from sysstat package)
sar -u 1 3CPU usage over 3 seconds
`dmesgtail`

Miscellaneous

CommandDescription
alias ll='ls -la'Create a custom shortcut
historyShow command history
!!Run previous command again
!100Run command number 100 from history
Ctrl + RReverse search in history
clearClear the terminal
man lsShow manual for ls
which bashShow full path of command