Free developer tool

Free Linux Commands Cheat Sheet

A Linux commands cheat sheet is a quick reference for the terminal commands you use to manage files, text, permissions, processes, disks, networks, packages, users and services. Search 103 common commands by name or task, see the syntax and flags that matter, copy a working example and spot the risky ones before you run them.

Showing 103 of 103 commands

Files & directories

ls

List files and folders in a directory.

Syntax: ls [options] [path]

-l
long format: permissions, owner, size, date
-a
include hidden dotfiles
-h
human-readable sizes with -l
-t
sort by modified time, newest first
$ ls -lah

cd

Change the current working directory.

Syntax: cd [directory]

~
go to your home directory
-
go back to the previous directory
..
go up one level
$ cd ~/projects/app

pwd

Print the full path of the current directory.

Syntax: pwd

-P
resolve symlinks to the physical path
$ pwd

mkdir

Create one or more directories.

Syntax: mkdir [options] directory...

-p
create parent folders as needed, no error if it exists
-v
print each folder created
$ mkdir -p src/components/ui

touch

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

Syntax: touch file...

-c
do not create the file if it is missing
$ touch notes.txt

cp

Copy files or directories.

Syntax: cp [options] source... destination

-r
copy directories recursively
-i
ask before overwriting
-a
archive mode: keep permissions, times and links
$ cp -r config/ config.bak/

Careful: Overwrites files at the destination without asking unless you add -i.

mv

Move or rename files and directories.

Syntax: mv [options] source... destination

-i
ask before overwriting
-n
never overwrite an existing file
-v
print each move
$ mv draft.md final.md

Careful: Overwrites a file with the same name at the destination unless you add -i or -n.

rm

Delete files or directories permanently. There is no trash.

Syntax: rm [options] file...

-r
delete directories and their contents
-i
ask before each deletion
-f
never ask, ignore missing files
$ rm -ri old-build/

Careful: Deleted files do not go to a trash folder. Check the path before using -r or -f, and never run rm -rf with a variable that might be empty.

rmdir

Remove an empty directory.

Syntax: rmdir directory...

-p
also remove empty parent directories
$ rmdir empty-folder

ln

Create links between files. Use -s for a symbolic link.

Syntax: ln -s target link_name

-s
make a symbolic (soft) link
-f
replace an existing link
$ ln -s /opt/app/current/bin/app ~/bin/app

find

Search for files by name, type, size, age and more, then optionally act on them.

Syntax: find [path] [tests] [actions]

-name
match a file name pattern (quote it)
-type f|d
files or directories only
-mtime -7
modified in the last 7 days
-size +100M
larger than 100 MB
$ find . -type f -name "*.log" -mtime +30

tree

Show a directory as an indented tree. Often needs installing first.

Syntax: tree [options] [path]

-L 2
limit depth to 2 levels
-a
include hidden files
-d
directories only
$ tree -L 2 src

stat

Show detailed file information: size, permissions, inode and timestamps.

Syntax: stat file

-c
custom output format
$ stat package.json

file

Identify a file's type from its contents, not its extension.

Syntax: file file...

-i
print the MIME type
$ file download.bin

View & search text

cat

Print a file's contents, or join several files.

Syntax: cat [options] file...

-n
number every line
-A
show tabs, line ends and hidden characters
$ cat /etc/os-release

less

Page through a long file. Press / to search and q to quit.

Syntax: less [options] file

-N
show line numbers
+F
follow the file like tail -f
$ less /var/log/syslog

head

Show the first lines of a file.

Syntax: head [-n count] file

-n 20
show the first 20 lines
$ head -n 20 data.csv

tail

Show the last lines of a file, or follow it as it grows.

Syntax: tail [options] file

-n 50
show the last 50 lines
-f
keep printing new lines as they are written
$ tail -f /var/log/nginx/error.log

grep

Search text for lines that match a pattern.

Syntax: grep [options] pattern [file...]

-r
search folders recursively
-i
ignore case
-n
show line numbers
-v
show lines that do not match
-E
extended regular expressions
$ grep -rn "TODO" src/

wc

Count lines, words and bytes.

Syntax: wc [options] file...

-l
lines only
-w
words only
-c
bytes only
$ wc -l access.log

sort

Sort lines of text.

Syntax: sort [options] file

-n
numeric sort
-r
reverse order
-u
drop duplicate lines
-k 2
sort by the second field
$ sort -n -r -k 2 scores.txt

uniq

Collapse repeated adjacent lines. Usually used after sort.

Syntax: uniq [options] [file]

-c
prefix each line with its count
-d
only print duplicated lines
$ sort ips.txt | uniq -c | sort -nr | head

cut

Extract columns or character ranges from each line.

Syntax: cut -d delimiter -f fields file

-d ,
use comma as the delimiter
-f 1,3
print fields 1 and 3
$ cut -d: -f1 /etc/passwd

awk

Process text by fields and patterns. Ideal for columns in logs and command output.

Syntax: awk 'pattern { action }' file

-F
set the field separator
$1, $NF
first and last field
$ awk '{ print $1 }' access.log | sort | uniq -c

sed

Find and replace or edit text in a stream or file.

Syntax: sed [options] 's/find/replace/g' file

-i
edit the file in place
-n
print only lines you ask for
-E
extended regular expressions
$ sed -i 's/http:/https:/g' links.txt

Careful: sed -i rewrites the file. Run it without -i first to preview, or use -i.bak to keep a backup. On macOS, -i needs an argument: sed -i '' ...

diff

Compare two files line by line.

Syntax: diff [options] file1 file2

-u
unified format, like git diff
-r
compare directories recursively
$ diff -u old.conf new.conf

tee

Write output to a file and the screen at the same time.

Syntax: command | tee [-a] file

-a
append instead of overwrite
$ npm run build 2>&1 | tee build.log

xargs

Turn input lines into arguments for another command.

Syntax: command | xargs [options] command

-0
read null-separated input (pair with find -print0)
-n 1
one argument per run
-P 4
run 4 in parallel
$ find . -name "*.tmp" -print0 | xargs -0 rm

Careful: Pairing xargs with rm deletes every matched file. Run the find part alone first to see the list.

Permissions & ownership

chmod

Change who can read, write or execute a file.

Syntax: chmod [options] mode file...

+x
make executable
755
owner rwx, group and others r-x
644
owner rw-, group and others r--
-R
apply recursively
$ chmod +x deploy.sh

Careful: chmod -R 777 makes files writable by every user. Use the narrowest permission that works.

chown

Change a file's owner and group.

Syntax: chown [options] user[:group] file...

-R
apply recursively
$ sudo chown -R www-data:www-data /var/www/site

chgrp

Change a file's group.

Syntax: chgrp [options] group file...

-R
apply recursively
$ sudo chgrp -R developers /srv/shared

umask

Show or set default permissions for new files.

Syntax: umask [mask]

-S
show symbolically, like u=rwx,g=rx,o=rx
$ umask 022

sudo

Run a command as root or another user.

Syntax: sudo [options] command

-u user
run as a specific user
-i
open a root login shell
!!
rerun the last command with sudo (sudo !!)
$ sudo systemctl restart nginx

Processes & jobs

ps

List running processes.

Syntax: ps [options]

aux
every process with user, CPU and memory
-ef
full list with parent PIDs
$ ps aux | grep node

top

Live view of processes, CPU and memory. Press q to quit.

Syntax: top

-u user
only that user's processes
M / P
sort by memory or CPU while running
$ top -u www-data

htop

Friendlier interactive process viewer. Usually needs installing first.

Syntax: htop

F6
choose sort column
F9
send a signal to the selected process
$ htop

kill

Send a signal to a process by PID. The default asks it to stop.

Syntax: kill [-signal] pid

-15
SIGTERM: ask nicely (default)
-9
SIGKILL: force stop, no cleanup
-l
list signal names
$ kill 4821

Careful: kill -9 gives the process no chance to save data. Try the default signal first.

pkill

Send a signal to processes by name.

Syntax: pkill [options] pattern

-f
match the full command line
-u user
only that user's processes
$ pkill -f "node server.js"

Careful: Every process whose name matches is signalled. Check with pgrep first.

pgrep

Find process IDs by name.

Syntax: pgrep [options] pattern

-a
show the full command line
-f
match the full command line
$ pgrep -a nginx

jobs

List background jobs in the current shell.

Syntax: jobs [-l]

-l
include process IDs
$ jobs -l

bg / fg

Resume a stopped job in the background or bring it to the foreground. Ctrl+Z stops the current job.

Syntax: bg [%job] · fg [%job]

%1
job number 1 from jobs
$ fg %1

nohup

Run a command that keeps going after you log out.

Syntax: nohup command [args] &

&
start it in the background
$ nohup ./backup.sh > backup.log 2>&1 &

nice

Start a command with lower or higher CPU priority.

Syntax: nice -n priority command

-n 10
lower priority (19 is lowest)
renice
change priority of a running PID
$ nice -n 10 tar -czf backup.tar.gz /data

lsof

List open files, including which process uses a port.

Syntax: lsof [options]

-i :3000
what is listening on port 3000
-p pid
files a process has open
$ sudo lsof -i :3000

System, disk & memory

df

Show free and used space on mounted disks.

Syntax: df [options] [path]

-h
human-readable sizes
-T
show filesystem type
$ df -h

du

Show how much space files and folders use.

Syntax: du [options] [path]

-s
one total per argument
-h
human-readable sizes
-d 1
one level deep
$ du -h -d 1 /var | sort -h

free

Show memory and swap usage.

Syntax: free [options]

-h
human-readable sizes
$ free -h

uname

Show kernel and system information.

Syntax: uname [options]

-a
everything
-r
kernel release only
$ uname -r

uptime

Show how long the system has run and its load averages.

Syntax: uptime

-p
pretty format
$ uptime

lsblk

List disks and partitions as a tree.

Syntax: lsblk [options]

-f
show filesystems, labels and UUIDs
$ lsblk -f

mount

Attach a filesystem to a folder, or list mounts.

Syntax: mount [device] [directory]

-t
filesystem type
umount
detach a mounted filesystem
$ sudo mount /dev/sdb1 /mnt/usb

date

Show or format the current date and time.

Syntax: date [+format]

+%F
YYYY-MM-DD
-u
UTC
$ date +%F-%H%M

hostnamectl

Show or set the hostname and OS details on systemd systems.

Syntax: hostnamectl [set-hostname name]

set-hostname
change the hostname
$ hostnamectl

dd

Copy raw data block by block, for example to write an image to a USB drive.

Syntax: dd if=input of=output [options]

bs=4M
block size
status=progress
show progress
$ sudo dd if=ubuntu.iso of=/dev/sdX bs=4M status=progress conv=fsync

Careful: A wrong of= target erases that disk immediately. Confirm the device with lsblk first.

Networking

ip

Show and change network interfaces, addresses and routes. Replaces ifconfig.

Syntax: ip [object] [command]

a
show addresses (ip a)
r
show routes (ip r)
link
show interfaces
$ ip a

ping

Check whether a host is reachable and measure round-trip time.

Syntax: ping [options] host

-c 4
stop after 4 packets
$ ping -c 4 example.com

curl

Make HTTP requests and download files.

Syntax: curl [options] url

-I
headers only
-L
follow redirects
-o file
save to a file
-X POST -d
send a POST body
$ curl -IL https://example.com

wget

Download files from the web.

Syntax: wget [options] url

-O file
save under this name
-c
resume a partial download
$ wget -c https://example.com/file.iso

ss

Show open sockets and listening ports. Replaces netstat.

Syntax: ss [options]

-t / -u
TCP or UDP
-l
listening only
-n
numeric ports
-p
show the process
$ sudo ss -tulpn

dig

Look up DNS records.

Syntax: dig [@server] name [type]

+short
answer only
MX / TXT / AAAA
record type
$ dig +short example.com MX

traceroute

Show each network hop to a host. May need installing.

Syntax: traceroute host

-n
no reverse DNS lookups
$ traceroute -n example.com

hostname

Show the machine's name or IP addresses.

Syntax: hostname [options]

-I
all IP addresses (Linux)
$ hostname -I

nc

Netcat: test whether a TCP or UDP port is open, or send raw data.

Syntax: nc [options] host port

-z
scan without sending data
-v
verbose
$ nc -zv db.internal 5432

ufw

Simple firewall front end on Ubuntu and Debian.

Syntax: sudo ufw [command]

status
show rules
allow 22/tcp
open a port
enable
turn the firewall on
$ sudo ufw allow 443/tcp

Careful: Enabling ufw over SSH without allowing port 22 first locks you out.

Archives & compression

tar

Create or extract .tar, .tar.gz and other archives.

Syntax: tar [options] archive [files]

-c / -x
create or extract
-z
gzip compression
-v
list files as they are processed
-f
archive file name (put it last)
-C dir
extract into a folder
$ tar -czvf site.tar.gz public/

tar -x

Extract a compressed tarball. Modern tar detects gzip, bzip2 and xz automatically.

Syntax: tar -xf archive.tar.gz [-C dir]

-t
list contents without extracting
-C
extract into a folder
$ tar -xzf site.tar.gz -C /tmp/site

gzip

Compress or decompress single files to .gz.

Syntax: gzip [options] file

-d
decompress
-k
keep the original file
-9
best compression
$ gzip -k access.log

zip / unzip

Create or extract .zip archives.

Syntax: zip -r archive.zip folder · unzip archive.zip

-r
include folders recursively
-d dir
unzip into a folder
-l
list contents
$ unzip release.zip -d release/

xz

High-ratio compression to .xz.

Syntax: xz [options] file

-d
decompress
-T0
use all CPU cores
$ xz -T0 -k dump.sql

Package managers

apt

Install and update software on Debian, Ubuntu and Mint.

Syntax: sudo apt [command] [package]

update
refresh package lists
upgrade
install updates
install
install a package
remove
uninstall a package
search
find a package
$ sudo apt update && sudo apt install -y htop

dnf

Install and update software on Fedora, RHEL, Rocky and AlmaLinux.

Syntax: sudo dnf [command] [package]

install
install a package
upgrade
install updates
remove
uninstall
search
find a package
$ sudo dnf install -y htop

pacman

Install and update software on Arch and Manjaro.

Syntax: sudo pacman [operation] [package]

-Syu
sync and upgrade everything
-S
install
-R
remove
-Ss
search
$ sudo pacman -S htop

zypper

Install and update software on openSUSE.

Syntax: sudo zypper [command] [package]

install
install a package
update
install updates
search
find a package
$ sudo zypper install htop

snap

Install sandboxed Snap packages, common on Ubuntu.

Syntax: sudo snap install package

--classic
allow classic confinement
list
installed snaps
$ sudo snap install code --classic

flatpak

Install sandboxed desktop apps from Flathub.

Syntax: flatpak install remote app-id

list
installed apps
update
update all apps
$ flatpak install flathub org.gimp.GIMP

dpkg

Low-level Debian package tool, for .deb files and package queries.

Syntax: dpkg [options] package

-i file.deb
install a downloaded .deb
-l
list installed packages
-L pkg
list files a package installed
$ sudo dpkg -i ./app_1.2.0_amd64.deb

Users & groups

whoami

Print the current user name.

Syntax: whoami

$ whoami

id

Show a user's UID, GID and groups.

Syntax: id [user]

-Gn
group names only
$ id deploy

useradd

Create a user account. On Debian, adduser is the friendlier wrapper.

Syntax: sudo useradd [options] user

-m
create a home directory
-s /bin/bash
login shell
-G group
extra groups
$ sudo useradd -m -s /bin/bash deploy

usermod

Change a user account, for example add it to a group.

Syntax: sudo usermod [options] user

-aG group
append to a group (keep -a!)
-L
lock the account
$ sudo usermod -aG docker deploy

Careful: Using -G without -a replaces all of the user's extra groups, which can remove sudo access.

passwd

Change a password.

Syntax: passwd [user]

-l
lock the password
-e
force a change at next login
$ sudo passwd deploy

groups

List the groups a user belongs to.

Syntax: groups [user]

$ groups deploy

su

Switch to another user in the current terminal.

Syntax: su [-] [user]

-
start a full login shell for that user
$ su - deploy

SSH & remote copy

ssh

Open a secure shell on a remote machine.

Syntax: ssh [options] user@host

-p 2222
non-default port
-i key
use a specific private key
-L 8080:localhost:80
forward a local port
$ ssh -i ~/.ssh/id_ed25519 deploy@203.0.113.10

ssh-keygen

Create an SSH key pair.

Syntax: ssh-keygen [options]

-t ed25519
modern key type
-C
comment, often your email
-f
output file
$ ssh-keygen -t ed25519 -C "you@example.com"

ssh-copy-id

Install your public key on a server for password-less login.

Syntax: ssh-copy-id [-i key.pub] user@host

-i
which public key to copy
$ ssh-copy-id deploy@203.0.113.10

scp

Copy files to or from a remote machine over SSH.

Syntax: scp [options] source destination

-r
copy folders
-P 2222
non-default port (capital P)
$ scp -r dist/ deploy@203.0.113.10:/var/www/site

rsync

Sync files efficiently, locally or over SSH. Only changed parts are sent.

Syntax: rsync [options] source destination

-a
archive mode: keep permissions and times
-v
verbose
-z
compress in transit
--delete
remove files missing from the source
-n
dry run
$ rsync -avz --dry-run dist/ deploy@203.0.113.10:/var/www/site/

Careful: --delete removes files at the destination. A trailing slash on the source changes what gets copied. Run with -n first.

Services & logs

systemctl

Start, stop, restart and inspect systemd services.

Syntax: sudo systemctl [command] service

status
state and recent logs
restart
stop then start
enable --now
start now and at boot
list-units --failed
failed services
$ sudo systemctl status nginx

journalctl

Read systemd logs.

Syntax: journalctl [options]

-u service
one service only
-f
follow new entries
-n 100
last 100 lines
--since "1 hour ago"
time filter
$ journalctl -u nginx -f

dmesg

Show kernel messages, such as hardware and driver errors.

Syntax: dmesg [options]

-T
human-readable timestamps
-w
follow new messages
$ sudo dmesg -T | tail -50

crontab

Schedule recurring commands for a user.

Syntax: crontab [-e | -l]

-e
edit your crontab
-l
list it
-r
delete it all
$ crontab -e

Careful: crontab -r deletes every scheduled job with no confirmation, and r sits next to e on the keyboard.

shutdown

Power off or reboot the machine, now or later.

Syntax: sudo shutdown [option] [time]

-r now
reboot now
-h +10
power off in 10 minutes
-c
cancel a scheduled shutdown
$ sudo shutdown -r +5

Careful: Ends every session on the machine, including other SSH users.

Shell & productivity

history

List previous commands. Ctrl+R searches them as you type.

Syntax: history [n]

!123
rerun command number 123
!!
rerun the last command
$ history | grep docker

alias

Create a shortcut for a longer command.

Syntax: alias name='command'

unalias
remove an alias
$ alias ll='ls -lah'

echo

Print text or variables.

Syntax: echo [text]

-n
no trailing newline
-e
interpret \n and \t
$ echo "$PATH"

export

Set an environment variable for this shell and its child processes.

Syntax: export NAME=value

env
list all variables
unset NAME
remove a variable
$ export NODE_ENV=production

which

Show the full path of the program a command runs.

Syntax: which command

type
shell built-in that also explains aliases
$ which python3

man

Open the manual page for a command.

Syntax: man command

-k word
search manual descriptions
--help
most commands also print short help
$ man rsync

watch

Rerun a command every few seconds and show the output full screen.

Syntax: watch [-n seconds] command

-n 5
every 5 seconds
-d
highlight changes
$ watch -n 5 df -h

clear

Clear the terminal screen. Ctrl+L does the same.

Syntax: clear

$ clear

source

Run a script in the current shell, for example to reload your config.

Syntax: source file

.
short form: . ~/.bashrc
$ source ~/.bashrc

> >> | 2>&1

Redirect and pipe: send output to a file, append to it, pass it to another command, or merge errors into output.

Syntax: command > file · command >> file · a | b

>
overwrite the file
>>
append to the file
|
pipe into the next command
2>&1
send errors to the same place as output
$ npm test > test.log 2>&1

Careful: A single > empties the file before writing. Use >> to append.

How to use this Linux command list

  1. 1. Search by command or task

    Type a command name such as tar, or a task such as port, disk space or permission.

  2. 2. Filter by category

    Pick a category such as Networking or Package managers to narrow the list.

  3. 3. Read the syntax and flags

    Check the syntax line, the common flags and any Careful note before you run it.

  4. 4. Copy the example

    Copy the example, change the file names or hosts to yours and run it in your terminal.

Linux commands FAQ

What are the basic Linux commands?

The basic Linux commands are ls (list files), cd (change directory), pwd (show where you are), mkdir (make a folder), cp (copy), mv (move or rename), rm (delete), cat and less (read files), grep (search text), sudo (run as admin) and man (read the manual). Learn these first and most other tasks build on them.

How do I find which process is using a port in Linux?

Run sudo ss -tulpn to list every listening port with its process, or sudo lsof -i :3000 for one port. Stop the process with kill followed by its PID.

How do I check disk space in Linux?

Run df -h to see free space on each disk, and du -h -d 1 /path | sort -h to see which folders use the most space.

How do I extract a tar.gz file in Linux?

Run tar -xzf file.tar.gz to extract it into the current folder, or add -C /target/folder to extract somewhere else. Use tar -tzf file.tar.gz to list the contents first.

Which Linux commands are dangerous?

rm -rf, dd, chmod -R 777, crontab -r, usermod -G without -a, rsync --delete and a single > redirect can all destroy data or access with no undo. This cheat sheet marks each one with a Careful note.

Do these commands work on Ubuntu, Fedora and Arch?

Yes. Core commands are the same on every distribution. Only package managers differ: apt on Debian and Ubuntu, dnf on Fedora and RHEL, pacman on Arch and zypper on openSUSE. Most also work in macOS Terminal and WSL on Windows, though some flags differ on macOS.

Stop retyping the same terminal chores

If you run the same build, deploy or cleanup commands every week, Tornic turns them into deterministic multi-step workflows that run on the Claude Code, Codex or Cursor CLI you already pay for.

Explore Tornic

Related free tools