← Back to DevOpsCommands

Linux

Linux Commands Cheat Sheet

Practical Linux commands for system administration, DevOps, troubleshooting, automation and SRE work.

19 categories171+ commands

Linux Command Categories

Jump directly to the Linux commands you need.

Showing 171 commands across 19 categories.

Linux System Information

9 commands
uname -a

Display detailed Linux kernel and system information.

hostname

Show the current system hostname.

hostnamectl

Display or manage hostname and operating system information.

uptime

Show how long the system has been running and load averages.

whoami

Display the currently logged-in username.

id

Display the current user's UID, GID and group memberships.

date

Display the current system date and time.

timedatectl

Display system time, timezone and time synchronization information.

lsb_release -a

Display Linux distribution information on systems that provide lsb_release.

Files and Directories

16 commands
pwd

Show the current working directory.

ls

List files and directories.

ls -la

List all files, including hidden files, with detailed information.

cd /var/log

Change to the /var/log directory.

cd ..

Move to the parent directory.

mkdir app

Create a directory named app.

mkdir -p app/config/logs

Create a directory structure including missing parent directories.

touch app.log

Create an empty file or update a file's timestamp.

cp file.txt backup.txt

Copy a file.

cp -r app backup-app

Copy a directory and its contents recursively.

mv old.txt new.txt

Move or rename a file.

rm file.txt

Delete a file.

rm -r app

Delete a directory and its contents recursively.

rm -rf app

Forcefully remove a directory and its contents. Use carefully.

file app.log

Identify the type of a file.

stat app.log

Display detailed file metadata such as permissions, size and timestamps.

File Permissions and Ownership

8 commands
ls -l

View file permissions, ownership and other metadata.

chmod 755 script.sh

Set read, write and execute permissions using numeric mode.

chmod +x script.sh

Add execute permission to a file.

chmod -R 755 app

Recursively change permissions under a directory.

chown user:user file.txt

Change the owner and group of a file.

chown -R user:user app

Recursively change ownership of a directory and its contents.

chgrp developers file.txt

Change the group ownership of a file.

umask

Display the current default permission mask for newly created files.

Users and Groups

10 commands
who

Show users currently logged into the system.

w

Show logged-in users and their current activity.

last

Display recent login history.

cat /etc/passwd

View local user account information.

cat /etc/group

View local group information.

sudo -l

Show commands the current user is allowed to run with sudo.

useradd devops

Create a new user account.

passwd devops

Set or change a user's password.

usermod -aG docker devops

Add a user to an additional group without removing existing memberships.

groupadd developers

Create a new group.

Processes and Jobs

12 commands
ps aux

Display running processes for all users.

ps -ef

Display processes using the full-format listing.

top

Interactively monitor running processes and system resources.

htop

Interactive process viewer with a more user-friendly interface when installed.

pgrep nginx

Find process IDs matching a process name or pattern.

pkill nginx

Send 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.

jobs

List jobs running in the current shell.

bg

Resume a stopped shell job in the background.

fg

Bring 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 commands
df -h

Check filesystem disk usage in human-readable format.

df -i

Check inode usage on mounted filesystems.

du -sh /var/log

Show the total size of a directory.

du -sh *

Show the size of items in the current directory.

du -ah /var/log | sort -h

Find large files and directories by sorting disk usage.

lsblk

List block devices such as disks and partitions.

mount

Display mounted filesystems.

findmnt

Display mounted filesystems in a structured view.

free -h

Check memory and swap usage in human-readable format.

Networking

11 commands
ip addr

Display network interfaces and IP addresses.

ip route

Display the system routing table.

ip link

Display and manage network interfaces.

ss -tulpn

Show listening TCP and UDP sockets with process information when permitted.

ping google.com

Test basic network connectivity to a host.

curl https://example.com

Make an HTTP request and display the response.

curl -I https://example.com

Fetch HTTP response headers without downloading the full body.

wget https://example.com/file.zip

Download a file from a URL.

dig example.com

Query DNS records when the dig utility is installed.

nslookup example.com

Query DNS information for a hostname.

traceroute example.com

Trace the network path to a destination when traceroute is installed.

Package Management

9 commands
apt update

Refresh package information on Debian and Ubuntu systems.

apt upgrade

Upgrade installed packages on Debian and Ubuntu systems.

apt install nginx

Install a package on Debian and Ubuntu systems.

apt remove nginx

Remove a package on Debian and Ubuntu systems.

dnf install nginx

Install a package on Fedora, RHEL-compatible and other DNF-based systems.

dnf update

Update packages on DNF-based systems.

yum install nginx

Install a package on older or compatible YUM-based systems.

which nginx

Show the executable path for a command when it is available in PATH.

command -v nginx

Check whether a command is available and show its resolved location.

systemd and Services

9 commands
systemctl status nginx

Check the status of a systemd service.

systemctl start nginx

Start a systemd service.

systemctl stop nginx

Stop a systemd service.

systemctl restart nginx

Restart a systemd service.

systemctl reload nginx

Reload a service configuration without fully restarting the service when supported.

systemctl enable nginx

Configure a service to start automatically during boot.

systemctl disable nginx

Prevent a service from automatically starting during boot.

systemctl is-active nginx

Check whether a service is currently active.

systemctl list-units --type=service

List loaded systemd service units.

Logs and Troubleshooting

10 commands
journalctl

View logs collected by systemd-journald.

journalctl -u nginx

View logs for a specific systemd service.

journalctl -u nginx -f

Follow new log entries for a systemd service.

journalctl -b

View logs from the current boot.

dmesg

Display kernel ring buffer messages.

tail -f /var/log/app.log

Continuously monitor new entries in an application log.

grep 'ERROR' app.log

Search a log file for lines containing ERROR.

grep -i 'error' app.log

Search for ERROR without case sensitivity.

free -h

Check available memory and swap.

uptime

Check system uptime and load averages.

Text Processing

11 commands
cat app.log

Display the contents of a file.

less app.log

Read a large file interactively page by page.

head -n 20 app.log

Show the first 20 lines of a file.

tail -n 20 app.log

Show the last 20 lines of a file.

grep 'ERROR' app.log

Search for matching lines in a file.

cut -d: -f1 /etc/passwd

Extract the first colon-separated field from each line.

sort names.txt

Sort lines alphabetically.

uniq names.txt

Remove adjacent duplicate lines.

wc -l app.log

Count the number of lines in a file.

awk '{print $1}' app.log

Print the first whitespace-separated field from each line.

sed 's/old/new/g' file.txt

Replace text using sed without modifying the original file by default.

Search and Find

7 commands
find /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 +100M

Find files larger than 100 MB.

grep -R 'ERROR' /var/log

Recursively search files under a directory for ERROR.

grep -n 'ERROR' app.log

Show matching lines together with their line numbers.

locate nginx.conf

Quickly search an indexed file database when locate is installed and its database is available.

which docker

Find the executable path for Docker if it is available in PATH.

SSH and Remote Administration

7 commands
ssh user@server

Connect to a remote Linux server using SSH.

ssh -p 2222 user@server

Connect to SSH using a custom port.

ssh -i ~/.ssh/id_rsa user@server

Connect 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 ed25519

Generate an Ed25519 SSH key pair.

Archives and Compression

7 commands
tar -czf backup.tar.gz app/

Create a gzip-compressed tar archive.

tar -xzf backup.tar.gz

Extract a gzip-compressed tar archive.

tar -tf backup.tar.gz

List the contents of a tar archive without extracting it.

gzip app.log

Compress a file using gzip.

gunzip app.log.gz

Decompress a gzip file.

zip -r backup.zip app/

Create a ZIP archive recursively.

unzip backup.zip

Extract a ZIP archive.

Environment Variables and Shell

8 commands
env

Display environment variables.

printenv PATH

Display the value of a specific environment variable.

export APP_ENV=production

Set an environment variable for the current shell and its child processes.

echo $PATH

Display the current executable search path.

echo $HOME

Display the current user's home directory.

source ~/.bashrc

Reload shell configuration into the current shell.

history

Display previously executed shell commands.

alias ll='ls -la'

Create a shell alias for a command.

Cron and Scheduling

5 commands
crontab -l

List the current user's cron jobs.

crontab -e

Edit the current user's cron jobs.

crontab -r

Remove the current user's cron table. Use carefully.

systemctl list-timers

List systemd timers configured on the system.

date

Check the current server date and time before troubleshooting scheduled tasks.

Performance and Monitoring

7 commands
top

Monitor CPU, memory and running processes interactively.

free -h

Display memory and swap usage.

vmstat 1

Display system performance statistics at regular intervals.

iostat

Display CPU and I/O statistics when sysstat is installed.

uptime

Display load averages and system uptime.

df -h

Check filesystem capacity.

du -sh *

Identify large files and directories in the current location.

Useful DevOps Commands

8 commands
watch -n 2 'kubectl get pods'

Repeatedly run a command at a fixed interval when watch is available.

history | grep docker

Search shell history for previously used Docker commands.

curl -I http://localhost:8080

Quickly check HTTP response headers from a local application.

ss -lntp

Check listening TCP ports and associated processes when permitted.

ps aux --sort=-%cpu | head

Show processes consuming the most CPU.

ps aux --sort=-%mem | head

Show processes consuming the most memory.

df -h | sort -k5 -h

Sort filesystem usage to help identify heavily used filesystems.

grep -R 'connection refused' /var/log

Search logs for a common service connectivity error.

Quick Troubleshooting

8 commands
df -h

Check whether a full filesystem is causing application failures.

free -h

Check whether memory or swap pressure is present.

top

Check CPU and process activity.

ps aux

Inspect currently running processes.

ss -tulpn

Check listening ports and network services.

systemctl --failed

List systemd units that are currently in a failed state.

journalctl -p err -b

View error-level journal messages from the current boot.

dmesg -T | tail -n 50

Inspect 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.