Menu

Tools

Linux Commands Tutorial

Learn 115+ essential Linux commands with examples and outputs

115 commands

ls

File

What it does

Lists files and directories. Use -l for detailed view, -a for hidden files, -h for readable sizes.

Example

$ ls -lah

Output

drwxr-xr-x 5 user group 4.0K Jan 11 15:00 Documents
-rw-r--r-- 1 user group  2.1M Jan 11 14:30 report.pdf

cd

File

What it does

Changes directory. Use .. for parent, ~ for home, - for previous directory.

Example

$ cd /var/www/html

Output

(changes directory)

pwd

File

What it does

Prints current working directory path.

Example

$ pwd

Output

/home/user/projects/my-app

mkdir

File

What it does

Creates new directories. Use -p to create parent directories.

Example

$ mkdir -p project/src/components

Output

(creates directories)

rm

File

What it does

Removes files/directories. Use -r for recursive, -f to force. BE CAREFUL!

Example

$ rm -rf old_folder

Output

(removes files)

cp

File

What it does

Copies files/directories. Use -r for directories, -i for interactive.

Example

$ cp -r source/ destination/

Output

(copies files)

mv

File

What it does

Moves or renames files and directories.

Example

$ mv old_name.txt new_name.txt

Output

(renames file)

touch

File

What it does

Creates empty files or updates timestamps.

Example

$ touch index.js package.json

Output

(creates files)

cat

File

What it does

Displays file contents. Can concatenate multiple files.

Example

$ cat config.json

Output

{
  "port": 3000,
  "host": "localhost"
}

less

File

What it does

Views files page by page. Space to scroll, q to quit.

Example

$ less /var/log/syslog

Output

(opens interactive viewer)

head

File

What it does

Shows first N lines of file (default 10).

Example

$ head -n 5 error.log

Output

[2026-01-11] ERROR: Connection failed
[2026-01-11] ERROR: Timeout

tail

File

What it does

Shows last N lines. Use -f to follow updates in real-time.

Example

$ tail -f /var/log/nginx/access.log

Output

192.168.1.1 - "GET /api HTTP/1.1" 200

ln

File

What it does

Creates links. Use -s for symbolic (soft) links.

Example

$ ln -s /usr/local/bin/node /usr/bin/node

Output

(creates symbolic link)

file

File

What it does

Determines file type based on content.

Example

$ file archive.tar.gz

Output

archive.tar.gz: gzip compressed data

stat

File

What it does

Displays detailed file/filesystem status.

Example

$ stat file.txt

Output

Size: 1024	Blocks: 8
Access: 2026-01-11 15:30:00

tree

File

What it does

Displays directory structure as tree. Install separately.

Example

$ tree -L 2

Output

.
├── src
│   ├── components
│   └── utils
└── package.json

basename

File

What it does

Extracts filename from path.

Example

$ basename /path/to/file.txt

Output

file.txt

dirname

File

What it does

Extracts directory path from full path.

Example

$ dirname /path/to/file.txt

Output

/path/to

readlink

File

What it does

Shows target of symbolic link.

Example

$ readlink -f /usr/bin/python

Output

/usr/bin/python3.10

realpath

File

What it does

Resolves absolute path of file.

Example

$ realpath ../file.txt

Output

/home/user/file.txt

uname

System

What it does

Prints system information. Use -a for all details.

Example

$ uname -a

Output

Linux server 5.15.0-91-generic x86_64 GNU/Linux

whoami

System

What it does

Shows current username.

Example

$ whoami

Output

ubuntu

hostname

System

What it does

Shows or sets system hostname. Use -I for IPs.

Example

$ hostname

Output

web-server-01

uptime

System

What it does

Shows system uptime and load averages.

Example

$ uptime

Output

15:30:12 up 7 days, 3:42, 2 users, load: 0.45, 0.38, 0.32

date

System

What it does

Shows/sets date and time. Supports custom formatting.

Example

$ date "+%Y-%m-%d %H:%M:%S"

Output

2026-01-11 15:30:45

free

System

What it does

Shows memory usage. Use -h for human-readable.

Example

$ free -h

Output

Mem:   7.8Gi   2.1Gi   3.2Gi

history

System

What it does

Shows command history. Use !number to re-execute.

Example

$ history | tail -5

Output

1001  cd /var/www
1002  ls -la
1003  vim index.html

man

System

What it does

Displays manual pages for commands.

Example

$ man ls

Output

(opens manual page)

echo

System

What it does

Prints text. Use > to write, >> to append to files.

Example

$ echo "Hello World"

Output

Hello World

alias

System

What it does

Creates command shortcuts. Add to ~/.bashrc for permanent.

Example

$ alias ll="ls -lah"

Output

(creates alias)

env

System

What it does

Shows environment variables.

Example

$ env | grep PATH

Output

PATH=/usr/local/bin:/usr/bin:/bin

export

System

What it does

Sets environment variables.

Example

$ export NODE_ENV=production

Output

(sets variable)

shutdown

System

What it does

Shuts down system. Use -h for halt, -r for reboot.

Example

$ shutdown -h now

Output

(system shutting down)

reboot

System

What it does

Reboots the system immediately.

Example

$ reboot

Output

(system rebooting)

systemctl

System

What it does

Manages systemd services. start/stop/restart/status.

Example

$ systemctl status nginx

Output

â—Ź nginx.service - running

ps

Process

What it does

Lists running processes. Use aux for all processes.

Example

$ ps aux | grep nginx

Output

www-data  1234  0.0  0.5  nginx: master

top

Process

What it does

Real-time process viewer. Press q to quit.

Example

$ top

Output

(interactive display)

htop

Process

What it does

Enhanced top with colors. Must install separately.

Example

$ htop

Output

(colorful interactive display)

kill

Process

What it does

Terminates process by PID. Use -9 for force kill.

Example

$ kill -9 1234

Output

(terminates process)

killall

Process

What it does

Kills all processes by name.

Example

$ killall node

Output

(terminates all node processes)

pkill

Process

What it does

Signals processes by pattern.

Example

$ pkill -f "python app.py"

Output

(terminates matching processes)

pgrep

Process

What it does

Finds process IDs by name pattern.

Example

$ pgrep nginx

Output

1234
1235
1236

bg

Process

What it does

Puts suspended job in background.

Example

$ bg %1

Output

[1]+ running	sleep 100 &

fg

Process

What it does

Brings background job to foreground.

Example

$ fg %1

Output

sleep 100

jobs

Process

What it does

Lists active background jobs.

Example

$ jobs

Output

[1]+ Running	sleep 100 &

nohup

Process

What it does

Runs command immune to hangups, with output to nohup.out.

Example

$ nohup python script.py &

Output

nohup: ignoring input and appending output

watch

Process

What it does

Executes command periodically and displays output.

Example

$ watch -n 1 "ls -l"

Output

(refreshes every 1 second)

ping

Network

What it does

Tests network connectivity. Use -c for count.

Example

$ ping -c 4 google.com

Output

64 bytes from 142.250.185.46: time=12.4 ms
4 packets, 0% loss

curl

Network

What it does

Transfers data from/to servers. Use -I for headers.

Example

$ curl -I https://api.github.com

Output

HTTP/2 200
server: GitHub.com

wget

Network

What it does

Downloads files from web. Supports resume.

Example

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

Output

file.zip saved [45234/45234]

ssh

Network

What it does

Securely connects to remote servers.

Example

$ ssh user@192.168.1.100

Output

user@192.168.1.100's password:

scp

Network

What it does

Securely copies files over SSH. Use -r for directories.

Example

$ scp file.txt user@host:/tmp/

Output

file.txt  100%  1024KB/s

rsync

Network

What it does

Syncs files efficiently. Only transfers differences.

Example

$ rsync -avz source/ user@host:dest/

Output

sent 1,234 bytes  received 56 bytes

ip

Network

What it does

Modern network configuration tool. Replaces ifconfig.

Example

$ ip addr show

Output

inet 192.168.1.100/24 brd 192.168.1.255

ifconfig

Network

What it does

Legacy network interface configuration tool.

Example

$ ifconfig eth0

Output

inet 192.168.1.100  netmask 255.255.255.0

netstat

Network

What it does

Shows network connections and statistics.

Example

$ netstat -tulpn | grep :80

Output

tcp 0 0.0.0.0:80 LISTEN 1234/nginx

ss

Network

What it does

Modern replacement for netstat. Faster.

Example

$ ss -tuln

Output

tcp   LISTEN  0.0.0.0:80

dig

Network

What it does

DNS lookup utility with detailed output.

Example

$ dig google.com

Output

;; ANSWER SECTION:
google.com. 142.250.185.46

nslookup

Network

What it does

Queries DNS servers interactively.

Example

$ nslookup google.com

Output

Address: 142.250.185.46

traceroute

Network

What it does

Traces packet route to network host.

Example

$ traceroute google.com

Output

1  192.168.1.1  1.234 ms
2  10.0.0.1  5.678 ms

nc

Network

What it does

Netcat - arbitrary TCP/UDP connections.

Example

$ nc -zv 127.0.0.1 80

Output

Connection to 127.0.0.1 80 port succeeded!

hostname

Network

What it does

Shows or sets system hostname.

Example

$ hostname -I

Output

192.168.1.100 172.17.0.1

arp

Network

What it does

Views/modifies ARP cache (IP-MAC mappings).

Example

$ arp -a

Output

192.168.1.1 at aa:bb:cc:dd:ee:ff

chmod

Permission

What it does

Changes file permissions. Read=4, Write=2, Execute=1.

Example

$ chmod 755 script.sh

Output

(changes permissions)

chown

Permission

What it does

Changes file owner and group.

Example

$ chown www-data:www-data /var/www

Output

(changes ownership)

chgrp

Permission

What it does

Changes group ownership only.

Example

$ chgrp admin file.txt

Output

(changes group)

umask

Permission

What it does

Sets default file creation permissions mask.

Example

$ umask 022

Output

(sets umask)

sudo

Permission

What it does

Executes command as superuser. Requires password.

Example

$ sudo apt update

Output

[sudo] password:
Hit:1 http://archive.ubuntu.com

su

Permission

What it does

Switches user. Use - for login shell.

Example

$ su -

Output

Password:

passwd

Permission

What it does

Changes user password.

Example

$ passwd john

Output

Enter new password:
passwd: password updated

grep

Search

What it does

Searches for patterns. Use -r for recursive, -i for case-insensitive.

Example

$ grep -rn "error" /var/log

Output

/var/log/app.log:42: ERROR: Database failed

find

Search

What it does

Searches files by name, type, size, permissions, etc.

Example

$ find /home -name "*.log" -type f

Output

/home/user/app.log
/home/user/error.log

locate

Search

What it does

Finds files by name using database. Very fast.

Example

$ locate nginx.conf

Output

/etc/nginx/nginx.conf

which

Search

What it does

Locates command executable path.

Example

$ which python3

Output

/usr/bin/python3

whereis

Search

What it does

Locates binary, source, and manual pages.

Example

$ whereis ls

Output

ls: /bin/ls /usr/share/man/man1/ls.1.gz

sed

Text

What it does

Stream editor for text transformation.

Example

$ sed "s/old/new/g" file.txt

Output

(shows file with old→new)

awk

Text

What it does

Pattern scanning and text processing language.

Example

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

Output

john 25
mary 30

sort

Text

What it does

Sorts lines. Use -n for numeric, -r for reverse.

Example

$ sort -n numbers.txt

Output

1
5
10
23
100

uniq

Text

What it does

Removes duplicate adjacent lines. Often used after sort.

Example

$ uniq file.txt

Output

(unique lines only)

cut

Text

What it does

Extracts sections from lines. Great for CSV.

Example

$ cut -d"," -f1 data.csv

Output

name
john
mary

wc

Text

What it does

Counts lines, words, bytes. Use -l for lines only.

Example

$ wc -l app.log

Output

1247 app.log

diff

Text

What it does

Compares files line by line.

Example

$ diff file1.txt file2.txt

Output

< old line
> new line

tr

Text

What it does

Translates or deletes characters.

Example

$ echo "hello" | tr [:lower:] [:upper:]

Output

HELLO

column

Text

What it does

Formats input into columns.

Example

$ column -t -s"," data.csv

Output

name  age  city
john  25   NY

tee

Text

What it does

Reads stdin and writes to stdout AND files.

Example

$ echo "log" | tee -a log.txt

Output

log
(also appends to log.txt)

tar

Archive

What it does

Archives files. -c create, -x extract, -z gzip, -v verbose.

Example

$ tar -czf backup.tar.gz /home/user

Output

(creates archive)

gzip

Archive

What it does

Compresses files using gzip algorithm.

Example

$ gzip largefile.txt

Output

(creates largefile.txt.gz)

gunzip

Archive

What it does

Decompresses gzip files.

Example

$ gunzip file.txt.gz

Output

(extracts to file.txt)

zip

Archive

What it does

Compresses to ZIP format. Use -r for directories.

Example

$ zip -r project.zip project/

Output

adding: project/index.js (deflated 65%)

unzip

Archive

What it does

Extracts ZIP archives. Use -l to list contents.

Example

$ unzip archive.zip

Output

inflating: file1.txt
inflating: file2.txt

bzip2

Archive

What it does

Compresses using bzip2 (better compression than gzip).

Example

$ bzip2 largefile.txt

Output

(creates largefile.txt.bz2)

xz

Archive

What it does

Compresses using LZMA (best compression).

Example

$ xz largefile.txt

Output

(creates largefile.txt.xz)

7z

Archive

What it does

7-Zip archiver with high compression. Install separately.

Example

$ 7z a archive.7z folder/

Output

Everything is Ok

df

Disk

What it does

Shows disk space usage for filesystems. Use -h for readable.

Example

$ df -h

Output

Filesystem   Size  Used Avail Use%
/dev/sda1     50G   35G   13G  74%

du

Disk

What it does

Estimates file/directory space usage.

Example

$ du -sh /var/log

Output

2.3G    /var/log

fdisk

Disk

What it does

Partition table manipulator. Use -l to list.

Example

$ fdisk -l

Output

Disk /dev/sda: 50 GiB

mount

Disk

What it does

Mounts filesystems.

Example

$ mount /dev/sdb1 /mnt

Output

(mounts device)

umount

Disk

What it does

Unmounts filesystems.

Example

$ umount /mnt

Output

(unmounts device)

lsblk

Disk

What it does

Lists block devices (disks, partitions).

Example

$ lsblk

Output

sda      8:0    0   50G  0 disk
├─sda1   8:1    0   49G  0 part /

blkid

Disk

What it does

Shows block device attributes (UUID, type).

Example

$ blkid

Output

/dev/sda1: UUID="abc-123" TYPE="ext4"

useradd

User

What it does

Creates new user. Use -m for home dir, -s for shell.

Example

$ useradd -m -s /bin/bash john

Output

(creates user)

usermod

User

What it does

Modifies user account. Use -aG to add to groups.

Example

$ usermod -aG docker john

Output

(adds user to docker group)

userdel

User

What it does

Deletes user. Use -r to remove home directory.

Example

$ userdel -r john

Output

(deletes user and home)

groupadd

User

What it does

Creates new group.

Example

$ groupadd developers

Output

(creates group)

groupdel

User

What it does

Deletes group.

Example

$ groupdel developers

Output

(deletes group)

id

User

What it does

Prints user and group IDs.

Example

$ id john

Output

uid=1001(john) gid=1001(john) groups=1001(john),27(sudo)

last

User

What it does

Shows last logged in users.

Example

$ last

Output

john  pts/0  192.168.1.50  Sat Jan 11 14:30 - 15:00

apt

Package

What it does

Debian package manager. update/install/remove packages.

Example

$ sudo apt update && sudo apt upgrade

Output

Reading package lists... Done
Upgrading 42 packages

apt-get

Package

What it does

Older Debian package manager. Still widely used.

Example

$ sudo apt-get install nginx

Output

Setting up nginx...
Done.

apt-cache

Package

What it does

Searches apt package database.

Example

$ apt-cache search python

Output

python3 - Interactive high-level language

dpkg

Package

What it does

Low-level Debian package tool.

Example

$ dpkg -l | grep nginx

Output

ii  nginx  1.18.0  high performance web server

yum

Package

What it does

Red Hat package manager.

Example

$ sudo yum install nginx

Output

Installing nginx...
Complete!

dnf

Package

What it does

Modern Red Hat package manager (replaces yum).

Example

$ sudo dnf install nginx

Output

Installing nginx...
Complete!

snap

Package

What it does

Universal Linux package manager.

Example

$ snap install code --classic

Output

code installed

flatpak

Package

What it does

Cross-distro app distribution system.

Example

$ flatpak install flathub org.gimp.GIMP

Output

Installing GIMP...
Done.

đź’ˇ Pro Tip

Most commands support --help flag to display usage information.

Example: ls --help

About Linux Commands

Quick reference for essential Linux terminal commands. Searchable, categorized, with syntax examples and common use cases. Perfect for developers, sysadmins, and anyone learning the command line.

The Linux command line is powerful but hard to memorize. This cheat sheet covers the most common commands for file management, process control, networking, and system administration—with examples you can copy directly.

How to use Linux Commands

1

Search for a command by name or what you want to do.

2

Or browse by category (files, processes, network, etc.).

3

View the command syntax and examples.

4

Click to copy the command.

5

Paste into your terminal.

Examples

File navigation

Moving around the filesystem:

pwd           # Print current directory
ls -la        # List all files, long format
cd /path/to   # Change directory
cd ~          # Go to home directory
cd ..         # Go up one level

File operations

Creating, moving, copying, deleting:

cp file.txt copy.txt     # Copy file
mv old.txt new.txt       # Rename/move file
rm file.txt              # Delete file
rm -rf directory/        # Delete directory
mkdir new_folder         # Create directory

Process management

Viewing and controlling processes:

ps aux           # List all processes
top              # Interactive process viewer
kill 1234        # Terminate process by PID
killall nginx    # Terminate by name
nohup cmd &      # Run in background

Features

100+ essential commands
Searchable by name or description
Categorized by function
Syntax and examples
Copy commands with one click
Links to full documentation

When to use this

  • •Quick reference while working in terminal
  • •Learning Linux basics
  • •System administration tasks
  • •Server management via SSH
  • •DevOps and deployment scripts
  • •Teaching command line skills

Common questions