Linux
Linux Commands Cheat Sheet
Practical Linux commands for system administration, DevOps, troubleshooting, automation and SRE work.
Linux Command Categories
Jump directly to the Linux commands you need.
Linux System Information
9 commands
View commands →Files and Directories
16 commands
View commands →File Permissions and Ownership
8 commands
View commands →Users and Groups
10 commands
View commands →Processes and Jobs
12 commands
View commands →Disk and Storage
9 commands
View commands →Networking
11 commands
View commands →Package Management
9 commands
View commands →systemd and Services
9 commands
View commands →Logs and Troubleshooting
10 commands
View commands →Text Processing
11 commands
View commands →Search and Find
7 commands
View commands →SSH and Remote Administration
7 commands
View commands →Archives and Compression
7 commands
View commands →Environment Variables and Shell
8 commands
View commands →Cron and Scheduling
5 commands
View commands →Performance and Monitoring
7 commands
View commands →Useful DevOps Commands
8 commands
View commands →Quick Troubleshooting
8 commands
View commands →Showing 171 commands across 19 categories.
Linux System Information
9 commandsuname -aDisplay detailed Linux kernel and system information.
hostnameShow the current system hostname.
hostnamectlDisplay or manage hostname and operating system information.
uptimeShow how long the system has been running and load averages.
whoamiDisplay the currently logged-in username.
idDisplay the current user's UID, GID and group memberships.
dateDisplay the current system date and time.
timedatectlDisplay system time, timezone and time synchronization information.
lsb_release -aDisplay Linux distribution information on systems that provide lsb_release.
Files and Directories
16 commandspwdShow the current working directory.
lsList files and directories.
ls -laList all files, including hidden files, with detailed information.
cd /var/logChange to the /var/log directory.
cd ..Move to the parent directory.
mkdir appCreate a directory named app.
mkdir -p app/config/logsCreate a directory structure including missing parent directories.
touch app.logCreate an empty file or update a file's timestamp.
cp file.txt backup.txtCopy a file.
cp -r app backup-appCopy a directory and its contents recursively.
mv old.txt new.txtMove or rename a file.
rm file.txtDelete a file.
rm -r appDelete a directory and its contents recursively.
rm -rf appForcefully remove a directory and its contents. Use carefully.
file app.logIdentify the type of a file.
stat app.logDisplay detailed file metadata such as permissions, size and timestamps.
File Permissions and Ownership
8 commandsls -lView file permissions, ownership and other metadata.
chmod 755 script.shSet read, write and execute permissions using numeric mode.
chmod +x script.shAdd execute permission to a file.
chmod -R 755 appRecursively change permissions under a directory.
chown user:user file.txtChange the owner and group of a file.
chown -R user:user appRecursively change ownership of a directory and its contents.
chgrp developers file.txtChange the group ownership of a file.
umaskDisplay the current default permission mask for newly created files.
Users and Groups
10 commandswhoShow users currently logged into the system.
wShow logged-in users and their current activity.
lastDisplay recent login history.
cat /etc/passwdView local user account information.
cat /etc/groupView local group information.
sudo -lShow commands the current user is allowed to run with sudo.
useradd devopsCreate a new user account.
passwd devopsSet or change a user's password.
usermod -aG docker devopsAdd a user to an additional group without removing existing memberships.
groupadd developersCreate a new group.
Processes and Jobs
12 commandsps auxDisplay running processes for all users.
ps -efDisplay processes using the full-format listing.
topInteractively monitor running processes and system resources.
htopInteractive process viewer with a more user-friendly interface when installed.
pgrep nginxFind process IDs matching a process name or pattern.
pkill nginxSend a signal to processes matching a name or pattern.
kill <PID>Send the default termination signal to a process.
kill -9 <PID>Forcefully terminate a process when normal termination does not work.
jobsList jobs running in the current shell.
bgResume a stopped shell job in the background.
fgBring a background shell job to the foreground.
nohup ./app.sh &Run a command so it can continue after the terminal session ends.
Disk and Storage
9 commandsdf -hCheck filesystem disk usage in human-readable format.
df -iCheck inode usage on mounted filesystems.
du -sh /var/logShow the total size of a directory.
du -sh *Show the size of items in the current directory.
du -ah /var/log | sort -hFind large files and directories by sorting disk usage.
lsblkList block devices such as disks and partitions.
mountDisplay mounted filesystems.
findmntDisplay mounted filesystems in a structured view.
free -hCheck memory and swap usage in human-readable format.
Networking
11 commandsip addrDisplay network interfaces and IP addresses.
ip routeDisplay the system routing table.
ip linkDisplay and manage network interfaces.
ss -tulpnShow listening TCP and UDP sockets with process information when permitted.
ping google.comTest basic network connectivity to a host.
curl https://example.comMake an HTTP request and display the response.
curl -I https://example.comFetch HTTP response headers without downloading the full body.
wget https://example.com/file.zipDownload a file from a URL.
dig example.comQuery DNS records when the dig utility is installed.
nslookup example.comQuery DNS information for a hostname.
traceroute example.comTrace the network path to a destination when traceroute is installed.
Package Management
9 commandsapt updateRefresh package information on Debian and Ubuntu systems.
apt upgradeUpgrade installed packages on Debian and Ubuntu systems.
apt install nginxInstall a package on Debian and Ubuntu systems.
apt remove nginxRemove a package on Debian and Ubuntu systems.
dnf install nginxInstall a package on Fedora, RHEL-compatible and other DNF-based systems.
dnf updateUpdate packages on DNF-based systems.
yum install nginxInstall a package on older or compatible YUM-based systems.
which nginxShow the executable path for a command when it is available in PATH.
command -v nginxCheck whether a command is available and show its resolved location.
systemd and Services
9 commandssystemctl status nginxCheck the status of a systemd service.
systemctl start nginxStart a systemd service.
systemctl stop nginxStop a systemd service.
systemctl restart nginxRestart a systemd service.
systemctl reload nginxReload a service configuration without fully restarting the service when supported.
systemctl enable nginxConfigure a service to start automatically during boot.
systemctl disable nginxPrevent a service from automatically starting during boot.
systemctl is-active nginxCheck whether a service is currently active.
systemctl list-units --type=serviceList loaded systemd service units.
Logs and Troubleshooting
10 commandsjournalctlView logs collected by systemd-journald.
journalctl -u nginxView logs for a specific systemd service.
journalctl -u nginx -fFollow new log entries for a systemd service.
journalctl -bView logs from the current boot.
dmesgDisplay kernel ring buffer messages.
tail -f /var/log/app.logContinuously monitor new entries in an application log.
grep 'ERROR' app.logSearch a log file for lines containing ERROR.
grep -i 'error' app.logSearch for ERROR without case sensitivity.
free -hCheck available memory and swap.
uptimeCheck system uptime and load averages.
Text Processing
11 commandscat app.logDisplay the contents of a file.
less app.logRead a large file interactively page by page.
head -n 20 app.logShow the first 20 lines of a file.
tail -n 20 app.logShow the last 20 lines of a file.
grep 'ERROR' app.logSearch for matching lines in a file.
cut -d: -f1 /etc/passwdExtract the first colon-separated field from each line.
sort names.txtSort lines alphabetically.
uniq names.txtRemove adjacent duplicate lines.
wc -l app.logCount the number of lines in a file.
awk '{print $1}' app.logPrint the first whitespace-separated field from each line.
sed 's/old/new/g' file.txtReplace text using sed without modifying the original file by default.
Search and Find
7 commandsfind /var/log -name '*.log'Find log files under /var/log.
find . -type f -name '*.yaml'Find YAML files under the current directory.
find . -type f -size +100MFind files larger than 100 MB.
grep -R 'ERROR' /var/logRecursively search files under a directory for ERROR.
grep -n 'ERROR' app.logShow matching lines together with their line numbers.
locate nginx.confQuickly search an indexed file database when locate is installed and its database is available.
which dockerFind the executable path for Docker if it is available in PATH.
SSH and Remote Administration
7 commandsssh user@serverConnect to a remote Linux server using SSH.
ssh -p 2222 user@serverConnect to SSH using a custom port.
ssh -i ~/.ssh/id_rsa user@serverConnect using a specific private key.
scp file.txt user@server:/tmp/Copy a local file to a remote server using SSH.
scp user@server:/tmp/file.txt .Copy a remote file to the local directory.
rsync -av ./app/ user@server:/opt/app/Synchronize files efficiently with a remote server.
ssh-keygen -t ed25519Generate an Ed25519 SSH key pair.
Archives and Compression
7 commandstar -czf backup.tar.gz app/Create a gzip-compressed tar archive.
tar -xzf backup.tar.gzExtract a gzip-compressed tar archive.
tar -tf backup.tar.gzList the contents of a tar archive without extracting it.
gzip app.logCompress a file using gzip.
gunzip app.log.gzDecompress a gzip file.
zip -r backup.zip app/Create a ZIP archive recursively.
unzip backup.zipExtract a ZIP archive.
Environment Variables and Shell
8 commandsenvDisplay environment variables.
printenv PATHDisplay the value of a specific environment variable.
export APP_ENV=productionSet an environment variable for the current shell and its child processes.
echo $PATHDisplay the current executable search path.
echo $HOMEDisplay the current user's home directory.
source ~/.bashrcReload shell configuration into the current shell.
historyDisplay previously executed shell commands.
alias ll='ls -la'Create a shell alias for a command.
Cron and Scheduling
5 commandscrontab -lList the current user's cron jobs.
crontab -eEdit the current user's cron jobs.
crontab -rRemove the current user's cron table. Use carefully.
systemctl list-timersList systemd timers configured on the system.
dateCheck the current server date and time before troubleshooting scheduled tasks.
Performance and Monitoring
7 commandstopMonitor CPU, memory and running processes interactively.
free -hDisplay memory and swap usage.
vmstat 1Display system performance statistics at regular intervals.
iostatDisplay CPU and I/O statistics when sysstat is installed.
uptimeDisplay load averages and system uptime.
df -hCheck filesystem capacity.
du -sh *Identify large files and directories in the current location.
Useful DevOps Commands
8 commandswatch -n 2 'kubectl get pods'Repeatedly run a command at a fixed interval when watch is available.
history | grep dockerSearch shell history for previously used Docker commands.
curl -I http://localhost:8080Quickly check HTTP response headers from a local application.
ss -lntpCheck listening TCP ports and associated processes when permitted.
ps aux --sort=-%cpu | headShow processes consuming the most CPU.
ps aux --sort=-%mem | headShow processes consuming the most memory.
df -h | sort -k5 -hSort filesystem usage to help identify heavily used filesystems.
grep -R 'connection refused' /var/logSearch logs for a common service connectivity error.
Quick Troubleshooting
8 commandsdf -hCheck whether a full filesystem is causing application failures.
free -hCheck whether memory or swap pressure is present.
topCheck CPU and process activity.
ps auxInspect currently running processes.
ss -tulpnCheck listening ports and network services.
systemctl --failedList systemd units that are currently in a failed state.
journalctl -p err -bView error-level journal messages from the current boot.
dmesg -T | tail -n 50Inspect recent kernel messages with human-readable timestamps.
DevOps Troubleshooting Workflow
# 1. Check disk df -h # 2. Check memory free -h # 3. Check CPU and processes top ps aux # 4. Check listening ports ss -tulpn # 5. Check failed services systemctl --failed # 6. Check service status systemctl status nginx # 7. Check service logs journalctl -u nginx # 8. Check recent system errors journalctl -p err -b # 9. Monitor application logs tail -f /var/log/app.log
DevOpsCommands Tip
When troubleshooting a Linux server, start with the basics: disk, memory, CPU, processes, network ports, services and logs. Establish what is failing before making changes to the system.