Ad 320×100
Developer

Linux Commands Cheat Sheet

Quick reference for essential Linux commands — files, permissions, networking, and more

ls -la

List all files including hidden, with detailed info

ls -lhS

List files sorted by size, human-readable

cd -

Switch to the previous directory

pwd

Print current working directory

mkdir -p dir1/dir2/dir3

Create nested directories recursively

cp -r src/ dest/

Copy directory recursively

mv old new

Move or rename a file/directory

rm -rf dir/

Remove directory and contents recursively (use with caution)

touch file.txt

Create an empty file or update its timestamp

ln -s target link

Create a symbolic link

find / -name '*.log' -mtime +7

Find .log files modified more than 7 days ago

find . -type f -size +100M

Find files larger than 100MB

locate filename

Quickly find files by name (uses pre-built index)

tree -L 2

Display directory tree, 2 levels deep

stat file.txt

Display detailed file information (size, permissions, timestamps)

file document.pdf

Determine the type of a file

cat file.txt

Display entire file contents

less file.txt

View file with pagination (q to quit)

head -n 20 file.txt

Show first 20 lines of a file

tail -f /var/log/syslog

Follow log file output in real time

realpath file.txt

Print the resolved absolute path

chmod 755 script.sh

Set rwxr-xr-x permissions (owner full, others read+execute)

chmod +x script.sh

Add execute permission for all users

chmod -R 644 dir/

Recursively set rw-r--r-- on all files in directory

chmod u+s executable

Set SUID bit — run as file owner

chown user:group file

Change file owner and group

chown -R user:group dir/

Recursively change ownership of directory

chgrp devs file.txt

Change file group ownership

umask 022

Set default permission mask for new files

getfacl file.txt

Display Access Control List for a file

setfacl -m u:user:rw file.txt

Set ACL to grant a user read/write access

grep -rn 'pattern' dir/

Recursively search for pattern with line numbers

grep -i 'error' log.txt

Case-insensitive search in a file

grep -v 'debug' log.txt

Show lines that do NOT match the pattern

grep -c 'error' log.txt

Count matching lines

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

Replace all occurrences of 'old' with 'new'

sed -i '10d' file.txt

Delete line 10 in-place

sed -n '5,10p' file.txt

Print only lines 5 through 10

awk '{print $1, $3}' file.txt

Print 1st and 3rd columns

awk -F: '{print $1}' /etc/passwd

Print first field using : as delimiter

sort -u file.txt

Sort and remove duplicate lines

sort -t: -k3 -n /etc/passwd

Sort by 3rd field numerically, delimited by :

uniq -c

Count consecutive duplicate lines

cut -d: -f1,3 /etc/passwd

Extract fields 1 and 3 with : delimiter

tr 'a-z' 'A-Z' < file.txt

Convert lowercase to uppercase

wc -l file.txt

Count lines in a file

diff file1 file2

Show differences between two files

tee output.txt

Read stdin and write to both stdout and file

xargs -I {} cp {} /dest/

Execute command for each line of input

ps aux

List all running processes with details

ps aux | grep nginx

Find processes matching a name

top

Interactive real-time process viewer

htop

Enhanced interactive process viewer (install separately)

kill <pid>

Send SIGTERM to a process (graceful shutdown)

kill -9 <pid>

Force kill a process (SIGKILL)

killall nginx

Kill all processes by name

pkill -f 'pattern'

Kill processes matching a pattern

bg %1

Resume suspended job in background

fg %1

Bring background job to foreground

jobs

List background and suspended jobs

nohup ./script.sh &

Run command immune to hangups in background

nice -n 10 ./cpu-heavy.sh

Start process with lower priority

renice -n 5 -p <pid>

Change priority of a running process

pgrep -la nginx

List PIDs and names of matching processes

lsof -i :8080

List processes using port 8080

curl -I https://example.com

Fetch HTTP headers only

curl -o file.zip https://example.com/file.zip

Download a file

curl -X POST -d '{"key":"val"}' -H 'Content-Type: application/json' url

Send a JSON POST request

wget -r -np https://example.com/

Recursively download a website

ping -c 4 google.com

Send 4 ICMP echo requests

traceroute google.com

Trace the route packets take to a host

ss -tulnp

Show listening TCP/UDP sockets with process info

netstat -tulnp

List listening ports and associated processes

ip addr show

Show all network interfaces and IP addresses

ip route show

Display the routing table

dig example.com

DNS lookup with detailed information

nslookup example.com

Query DNS for a domain

scp file.txt user@host:/path/

Copy file to remote host via SSH

rsync -avz src/ user@host:/dest/

Sync files to remote with compression

ssh user@host

Connect to remote host via SSH

ssh -L 8080:localhost:80 user@host

Create SSH tunnel (local port forwarding)

nc -zv host 22

Test if a port is open on a host

uname -a

Display all system information

hostname

Show or set the system hostname

uptime

Show how long the system has been running

whoami

Print the current username

id

Display user ID, group ID, and groups

lsb_release -a

Show Linux distribution information

cat /etc/os-release

Display OS release details

free -h

Show memory usage in human-readable format

lscpu

Display CPU architecture information

lsblk

List all block devices (disks and partitions)

dmesg | tail -20

Show last 20 kernel messages

date

Display current date and time

timedatectl

Show and configure system time settings

env

Print all environment variables

printenv PATH

Print a specific environment variable

tar -czf archive.tar.gz dir/

Create gzip-compressed tar archive

tar -xzf archive.tar.gz

Extract gzip tar archive

tar -cjf archive.tar.bz2 dir/

Create bzip2-compressed tar archive

tar -xjf archive.tar.bz2

Extract bzip2 tar archive

tar -tf archive.tar.gz

List contents of tar archive without extracting

gzip file.txt

Compress file (replaces original with file.txt.gz)

gunzip file.txt.gz

Decompress gzip file

zip -r archive.zip dir/

Create zip archive of a directory

unzip archive.zip -d /dest/

Extract zip archive to destination

xz file.txt

Compress file with xz (high compression ratio)

unxz file.txt.xz

Decompress xz file

zcat file.gz

View contents of a gzip file without extracting

sudo useradd -m -s /bin/bash user

Create user with home directory and bash shell

sudo userdel -r user

Delete user and their home directory

sudo usermod -aG docker user

Add user to a group (append)

sudo passwd user

Set or change a user's password

su - user

Switch to another user with login shell

sudo -i

Open root shell

groups user

Show groups a user belongs to

who

Show who is currently logged in

w

Show logged-in users and their activity

last

Show recent login history

sudo visudo

Safely edit the sudoers file

df -h

Show disk space usage for all mounted filesystems

du -sh dir/

Show total size of a directory

du -h --max-depth=1

Show sizes of immediate subdirectories

du -ah . | sort -rh | head -20

Find 20 largest files/dirs in current directory

sudo mount /dev/sdb1 /mnt

Mount a partition

sudo umount /mnt

Unmount a filesystem

sudo fdisk -l

List all disk partitions

lsblk -f

List block devices with filesystem info

blkid

Display block device attributes (UUID, type)

ncdu

Interactive disk usage analyzer (install separately)

sudo apt update

Update package index (Debian/Ubuntu)

sudo apt upgrade

Upgrade all installed packages

sudo apt install <package>

Install a package

sudo apt remove <package>

Remove a package (keep config)

sudo apt purge <package>

Remove a package and its configuration

sudo apt autoremove

Remove unused dependency packages

apt search <keyword>

Search for packages by keyword

apt show <package>

Show detailed package information

dpkg -l | grep <package>

Check if a package is installed

dpkg -i package.deb

Install a .deb package file

sudo snap install <package>

Install a snap package

snap list

List installed snap packages

Commands shown may vary slightly between Linux distributions.

Ad 320×100

Linux Commands Cheat Sheet

A free, searchable Linux command cheat sheet with the most useful commands, flags, and shortcuts in one place. Quickly look up syntax, copy commands, and learn the Linux terminal faster — perfect for beginners and a handy reference for experienced users.

FAQ

Is this Linux command cheat sheet free?
Yes. The entire cheat sheet is free to browse and copy from, with no sign-up required.
Can I search for a specific command?
Yes. Use the search to filter the Linux command commands instantly and jump straight to the syntax you need.
Who is the Linux command cheat sheet for?
It suits everyone from newcomers learning the Linux terminal to power users who want a quick reminder of less-used flags and shortcuts.