Linux Command Reference

~80 essential Linux commands organized by category. Search by command name, description, or example.

File System

ls

List directory contents

ls [options] [path]
Examples:
  • $ ls -la
  • $ ls -lh /var
  • $ ls -t

cd

Change directory

cd [directory]
Examples:
  • $ cd /home
  • $ cd ..
  • $ cd ~

pwd

Print working directory

pwd
Examples:
  • $ pwd

mkdir

Create directory

mkdir [options] directory
Examples:
  • $ mkdir project
  • $ mkdir -p a/b/c
  • $ mkdir -m 755 dir

rm

Remove files/directories

rm [options] file
Examples:
  • $ rm file.txt
  • $ rm -rf directory
  • $ rm -i *.log

cp

Copy files/directories

cp [options] source dest
Examples:
  • $ cp file.txt backup/
  • $ cp -r dir1 dir2
  • $ cp -p file backup

mv

Move/rename files

mv [options] source dest
Examples:
  • $ mv file.txt newname.txt
  • $ mv *.txt folder/

find

Search for files

find path [expression]
Examples:
  • $ find . -name '*.txt'
  • $ find /var -mtime -7
  • $ find . -type f -size +1M

locate

Find files by name (indexed)

locate pattern
Examples:
  • $ locate config
  • $ locate -i '*.pdf'

du

Disk usage

du [options] [path]
Examples:
  • $ du -sh .
  • $ du -h --max-depth=1
  • $ du -ah

df

Disk free space

df [options] [path]
Examples:
  • $ df -h
  • $ df -i
  • $ df -T

File Content

cat

Concatenate and display files

cat [options] file
Examples:
  • $ cat file.txt
  • $ cat file1 file2 > combined
  • $ cat -n file.txt

head

Output first lines

head [options] file
Examples:
  • $ head file.txt
  • $ head -n 20 file.txt
  • $ head -c 100 file

tail

Output last lines

tail [options] file
Examples:
  • $ tail file.txt
  • $ tail -f log.txt
  • $ tail -n 50 file

less

Page through file

less [options] file
Examples:
  • $ less file.txt
  • $ less +F log.txt

more

Page through file (simpler)

more file
Examples:
  • $ more file.txt

grep

Search text with regex

grep [options] pattern file
Examples:
  • $ grep 'error' log.txt
  • $ grep -r 'TODO' .
  • $ grep -i 'warning' file

sed

Stream editor

sed [options] 'script' file
Examples:
  • $ sed 's/old/new/g' file
  • $ sed -i.bak '1d' file
  • $ sed -n '10,20p' file

awk

Pattern scanning and processing

awk 'pattern {action}' file
Examples:
  • $ awk '{print $1}' file
  • $ awk -F',' '{print $2}' csv
  • $ awk '/error/ {count++} END {print count}'

sort

Sort lines

sort [options] file
Examples:
  • $ sort file.txt
  • $ sort -n numbers.txt
  • $ sort -t',' -k2 file.csv

wc

Word/line/byte count

wc [options] file
Examples:
  • $ wc -l file.txt
  • $ wc -w file.txt
  • $ wc -c file

diff

Compare files line by line

diff [options] file1 file2
Examples:
  • $ diff file1 file2
  • $ diff -u old new
  • $ diff -r dir1 dir2

Permissions

chmod

Change file permissions

chmod [options] mode file
Examples:
  • $ chmod 755 script.sh
  • $ chmod +x file
  • $ chmod -R 644 dir/

chown

Change file owner

chown [options] owner[:group] file
Examples:
  • $ chown user file
  • $ chown user:group file
  • $ chown -R user dir/

chgrp

Change file group

chgrp [options] group file
Examples:
  • $ chgrp www-data file
  • $ chgrp -R dev dir/

umask

Set default file permissions

umask [mode]
Examples:
  • $ umask
  • $ umask 022
  • $ umask 002

Process

ps

Report process status

ps [options]
Examples:
  • $ ps aux
  • $ ps -ef
  • $ ps -u $USER

top

Display processes (interactive)

top [options]
Examples:
  • $ top
  • $ top -u www-data
  • $ top -p 1234

kill

Terminate process

kill [options] PID
Examples:
  • $ kill 1234
  • $ kill -9 1234
  • $ kill -SIGTERM 1234

bg

Resume job in background

bg [job]
Examples:
  • $ bg
  • $ bg %1

fg

Bring job to foreground

fg [job]
Examples:
  • $ fg
  • $ fg %1

jobs

List active jobs

jobs [options]
Examples:
  • $ jobs
  • $ jobs -l

nohup

Run immune to hangups

nohup command [args]
Examples:
  • $ nohup ./script.sh &
  • $ nohup python app.py > out.log 2>&1

nice

Run with adjusted priority

nice [options] command
Examples:
  • $ nice -n 19 ./heavy.sh
  • $ nice -n -10 ./critical

Network

ping

Test network connectivity

ping [options] host
Examples:
  • $ ping google.com
  • $ ping -c 4 8.8.8.8
  • $ ping -i 2 host

curl

Transfer data from URL

curl [options] URL
Examples:
  • $ curl https://example.com
  • $ curl -o file.zip URL
  • $ curl -X POST -d 'data' URL

wget

Download files from web

wget [options] URL
Examples:
  • $ wget https://example.com/file.zip
  • $ wget -O out.zip URL
  • $ wget -r -np URL

ssh

Secure shell remote login

ssh [options] user@host
Examples:
  • $ ssh user@server.com
  • $ ssh -i key.pem user@host
  • $ ssh -p 2222 user@host

scp

Secure copy

scp [options] source dest
Examples:
  • $ scp file user@host:/path
  • $ scp -r dir user@host:/path
  • $ scp user@host:file .

netstat

Network statistics

netstat [options]
Examples:
  • $ netstat -tuln
  • $ netstat -an
  • $ netstat -r

ifconfig

Configure network interfaces

ifconfig [interface] [options]
Examples:
  • $ ifconfig
  • $ ifconfig eth0 up
  • $ ifconfig eth0 192.168.1.10

ip

Show/manipulate routing, devices

ip [options] object command
Examples:
  • $ ip addr
  • $ ip route
  • $ ip link show

dig

DNS lookup utility

dig [options] name [type]
Examples:
  • $ dig example.com
  • $ dig example.com MX
  • $ dig @8.8.8.8 example.com

nslookup

Query DNS

nslookup [options] name
Examples:
  • $ nslookup example.com
  • $ nslookup -type=MX example.com

System

uname

Print system information

uname [options]
Examples:
  • $ uname -a
  • $ uname -r
  • $ uname -m

hostname

Show/set system hostname

hostname [options] [name]
Examples:
  • $ hostname
  • $ hostname -I

uptime

System uptime and load

uptime
Examples:
  • $ uptime

free

Memory usage

free [options]
Examples:
  • $ free -h
  • $ free -m

lsblk

List block devices

lsblk [options]
Examples:
  • $ lsblk
  • $ lsblk -f

mount

Mount filesystems

mount [options] device dir
Examples:
  • $ mount
  • $ mount /dev/sdb1 /mnt
  • $ mount -t nfs server:/path /mnt

systemctl

Control systemd

systemctl [command] [unit]
Examples:
  • $ systemctl status nginx
  • $ systemctl start nginx
  • $ systemctl enable nginx

Package Management

apt

Debian/Ubuntu package manager

apt [command] [options]
Examples:
  • $ apt update
  • $ apt install nginx
  • $ apt remove package

yum

RHEL/CentOS package manager

yum [command] [options]
Examples:
  • $ yum install nginx
  • $ yum update
  • $ yum remove package

dnf

Fedora package manager

dnf [command] [options]
Examples:
  • $ dnf install nginx
  • $ dnf search package

pacman

Arch package manager

pacman [options] [package]
Examples:
  • $ pacman -S nginx
  • $ pacman -Syu
  • $ pacman -Qs search

brew

macOS/Linux package manager

brew [command] [formula]
Examples:
  • $ brew install nginx
  • $ brew update
  • $ brew list

Compression

tar

Archive files

tar [options] archive [files]
Examples:
  • $ tar -cvf archive.tar dir/
  • $ tar -xvf archive.tar
  • $ tar -czvf archive.tar.gz dir/

gzip

Compress files

gzip [options] file
Examples:
  • $ gzip file
  • $ gzip -d file.gz
  • $ gzip -9 file

zip

Create ZIP archive

zip [options] archive files
Examples:
  • $ zip archive.zip file1 file2
  • $ zip -r archive.zip dir/

unzip

Extract ZIP archive

unzip [options] archive
Examples:
  • $ unzip archive.zip
  • $ unzip -l archive.zip
  • $ unzip -d /path archive.zip

Users

useradd

Add user account

useradd [options] username
Examples:
  • $ useradd john
  • $ useradd -m -s /bin/bash john

passwd

Change user password

passwd [username]
Examples:
  • $ passwd
  • $ passwd john

su

Switch user

su [options] [username]
Examples:
  • $ su root
  • $ su - john
  • $ su -c 'command' root

sudo

Execute as superuser

sudo [options] command
Examples:
  • $ sudo apt update
  • $ sudo -u www-data command
  • $ sudo -i

whoami

Print current user

whoami
Examples:
  • $ whoami

id

Print user/group IDs

id [options] [user]
Examples:
  • $ id
  • $ id root
  • $ id -Gn

groups

Print group memberships

groups [user]
Examples:
  • $ groups
  • $ groups john