Linux Commands Tutorial
Learn 115+ essential Linux commands with examples and outputs
ls
What it does
Lists files and directories. Use -l for detailed view, -a for hidden files, -h for readable sizes.
Example
$ ls -lahOutput
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
What it does
Changes directory. Use .. for parent, ~ for home, - for previous directory.
Example
$ cd /var/www/htmlOutput
(changes directory)
pwd
What it does
Prints current working directory path.
Example
$ pwdOutput
/home/user/projects/my-app
mkdir
What it does
Creates new directories. Use -p to create parent directories.
Example
$ mkdir -p project/src/componentsOutput
(creates directories)
rm
What it does
Removes files/directories. Use -r for recursive, -f to force. BE CAREFUL!
Example
$ rm -rf old_folderOutput
(removes files)
cp
What it does
Copies files/directories. Use -r for directories, -i for interactive.
Example
$ cp -r source/ destination/Output
(copies files)
mv
What it does
Moves or renames files and directories.
Example
$ mv old_name.txt new_name.txtOutput
(renames file)
touch
What it does
Creates empty files or updates timestamps.
Example
$ touch index.js package.jsonOutput
(creates files)
cat
What it does
Displays file contents. Can concatenate multiple files.
Example
$ cat config.jsonOutput
{
"port": 3000,
"host": "localhost"
}less
What it does
Views files page by page. Space to scroll, q to quit.
Example
$ less /var/log/syslogOutput
(opens interactive viewer)
head
What it does
Shows first N lines of file (default 10).
Example
$ head -n 5 error.logOutput
[2026-01-11] ERROR: Connection failed [2026-01-11] ERROR: Timeout
tail
What it does
Shows last N lines. Use -f to follow updates in real-time.
Example
$ tail -f /var/log/nginx/access.logOutput
192.168.1.1 - "GET /api HTTP/1.1" 200
ln
What it does
Creates links. Use -s for symbolic (soft) links.
Example
$ ln -s /usr/local/bin/node /usr/bin/nodeOutput
(creates symbolic link)
file
What it does
Determines file type based on content.
Example
$ file archive.tar.gzOutput
archive.tar.gz: gzip compressed data
stat
What it does
Displays detailed file/filesystem status.
Example
$ stat file.txtOutput
Size: 1024 Blocks: 8 Access: 2026-01-11 15:30:00
tree
What it does
Displays directory structure as tree. Install separately.
Example
$ tree -L 2Output
. ├── src │ ├── components │ └── utils └── package.json
basename
What it does
Extracts filename from path.
Example
$ basename /path/to/file.txtOutput
file.txt
dirname
What it does
Extracts directory path from full path.
Example
$ dirname /path/to/file.txtOutput
/path/to
readlink
What it does
Shows target of symbolic link.
Example
$ readlink -f /usr/bin/pythonOutput
/usr/bin/python3.10
realpath
What it does
Resolves absolute path of file.
Example
$ realpath ../file.txtOutput
/home/user/file.txt
uname
What it does
Prints system information. Use -a for all details.
Example
$ uname -aOutput
Linux server 5.15.0-91-generic x86_64 GNU/Linux
whoami
What it does
Shows current username.
Example
$ whoamiOutput
ubuntu
hostname
What it does
Shows or sets system hostname. Use -I for IPs.
Example
$ hostnameOutput
web-server-01
uptime
What it does
Shows system uptime and load averages.
Example
$ uptimeOutput
15:30:12 up 7 days, 3:42, 2 users, load: 0.45, 0.38, 0.32
date
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
What it does
Shows memory usage. Use -h for human-readable.
Example
$ free -hOutput
Mem: 7.8Gi 2.1Gi 3.2Gi
history
What it does
Shows command history. Use !number to re-execute.
Example
$ history | tail -5Output
1001 cd /var/www 1002 ls -la 1003 vim index.html
man
What it does
Displays manual pages for commands.
Example
$ man lsOutput
(opens manual page)
echo
What it does
Prints text. Use > to write, >> to append to files.
Example
$ echo "Hello World"Output
Hello World
alias
What it does
Creates command shortcuts. Add to ~/.bashrc for permanent.
Example
$ alias ll="ls -lah"Output
(creates alias)
env
What it does
Shows environment variables.
Example
$ env | grep PATHOutput
PATH=/usr/local/bin:/usr/bin:/bin
export
What it does
Sets environment variables.
Example
$ export NODE_ENV=productionOutput
(sets variable)
shutdown
What it does
Shuts down system. Use -h for halt, -r for reboot.
Example
$ shutdown -h nowOutput
(system shutting down)
reboot
What it does
Reboots the system immediately.
Example
$ rebootOutput
(system rebooting)
systemctl
What it does
Manages systemd services. start/stop/restart/status.
Example
$ systemctl status nginxOutput
● nginx.service - running
ps
What it does
Lists running processes. Use aux for all processes.
Example
$ ps aux | grep nginxOutput
www-data 1234 0.0 0.5 nginx: master
top
What it does
Real-time process viewer. Press q to quit.
Example
$ topOutput
(interactive display)
htop
What it does
Enhanced top with colors. Must install separately.
Example
$ htopOutput
(colorful interactive display)
kill
What it does
Terminates process by PID. Use -9 for force kill.
Example
$ kill -9 1234Output
(terminates process)
killall
What it does
Kills all processes by name.
Example
$ killall nodeOutput
(terminates all node processes)
pkill
What it does
Signals processes by pattern.
Example
$ pkill -f "python app.py"Output
(terminates matching processes)
pgrep
What it does
Finds process IDs by name pattern.
Example
$ pgrep nginxOutput
1234 1235 1236
bg
What it does
Puts suspended job in background.
Example
$ bg %1Output
[1]+ running sleep 100 &
fg
What it does
Brings background job to foreground.
Example
$ fg %1Output
sleep 100
jobs
What it does
Lists active background jobs.
Example
$ jobsOutput
[1]+ Running sleep 100 &
nohup
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
What it does
Executes command periodically and displays output.
Example
$ watch -n 1 "ls -l"Output
(refreshes every 1 second)
ping
What it does
Tests network connectivity. Use -c for count.
Example
$ ping -c 4 google.comOutput
64 bytes from 142.250.185.46: time=12.4 ms 4 packets, 0% loss
curl
What it does
Transfers data from/to servers. Use -I for headers.
Example
$ curl -I https://api.github.comOutput
HTTP/2 200 server: GitHub.com
wget
What it does
Downloads files from web. Supports resume.
Example
$ wget https://example.com/file.zipOutput
file.zip saved [45234/45234]
ssh
What it does
Securely connects to remote servers.
Example
$ ssh user@192.168.1.100Output
user@192.168.1.100's password:
scp
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
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
What it does
Modern network configuration tool. Replaces ifconfig.
Example
$ ip addr showOutput
inet 192.168.1.100/24 brd 192.168.1.255
ifconfig
What it does
Legacy network interface configuration tool.
Example
$ ifconfig eth0Output
inet 192.168.1.100 netmask 255.255.255.0
netstat
What it does
Shows network connections and statistics.
Example
$ netstat -tulpn | grep :80Output
tcp 0 0.0.0.0:80 LISTEN 1234/nginx
ss
What it does
Modern replacement for netstat. Faster.
Example
$ ss -tulnOutput
tcp LISTEN 0.0.0.0:80
dig
What it does
DNS lookup utility with detailed output.
Example
$ dig google.comOutput
;; ANSWER SECTION: google.com. 142.250.185.46
nslookup
What it does
Queries DNS servers interactively.
Example
$ nslookup google.comOutput
Address: 142.250.185.46
traceroute
What it does
Traces packet route to network host.
Example
$ traceroute google.comOutput
1 192.168.1.1 1.234 ms 2 10.0.0.1 5.678 ms
nc
What it does
Netcat - arbitrary TCP/UDP connections.
Example
$ nc -zv 127.0.0.1 80Output
Connection to 127.0.0.1 80 port succeeded!
hostname
What it does
Shows or sets system hostname.
Example
$ hostname -IOutput
192.168.1.100 172.17.0.1
arp
What it does
Views/modifies ARP cache (IP-MAC mappings).
Example
$ arp -aOutput
192.168.1.1 at aa:bb:cc:dd:ee:ff
chmod
What it does
Changes file permissions. Read=4, Write=2, Execute=1.
Example
$ chmod 755 script.shOutput
(changes permissions)
chown
What it does
Changes file owner and group.
Example
$ chown www-data:www-data /var/wwwOutput
(changes ownership)
chgrp
What it does
Changes group ownership only.
Example
$ chgrp admin file.txtOutput
(changes group)
umask
What it does
Sets default file creation permissions mask.
Example
$ umask 022Output
(sets umask)
sudo
What it does
Executes command as superuser. Requires password.
Example
$ sudo apt updateOutput
[sudo] password: Hit:1 http://archive.ubuntu.com
su
What it does
Switches user. Use - for login shell.
Example
$ su -Output
Password:
passwd
What it does
Changes user password.
Example
$ passwd johnOutput
Enter new password: passwd: password updated
grep
What it does
Searches for patterns. Use -r for recursive, -i for case-insensitive.
Example
$ grep -rn "error" /var/logOutput
/var/log/app.log:42: ERROR: Database failed
find
What it does
Searches files by name, type, size, permissions, etc.
Example
$ find /home -name "*.log" -type fOutput
/home/user/app.log /home/user/error.log
locate
What it does
Finds files by name using database. Very fast.
Example
$ locate nginx.confOutput
/etc/nginx/nginx.conf
which
What it does
Locates command executable path.
Example
$ which python3Output
/usr/bin/python3
whereis
What it does
Locates binary, source, and manual pages.
Example
$ whereis lsOutput
ls: /bin/ls /usr/share/man/man1/ls.1.gz
sed
What it does
Stream editor for text transformation.
Example
$ sed "s/old/new/g" file.txtOutput
(shows file with old→new)
awk
What it does
Pattern scanning and text processing language.
Example
$ awk "{print $1, $3}" file.txtOutput
john 25 mary 30
sort
What it does
Sorts lines. Use -n for numeric, -r for reverse.
Example
$ sort -n numbers.txtOutput
1 5 10 23 100
uniq
What it does
Removes duplicate adjacent lines. Often used after sort.
Example
$ uniq file.txtOutput
(unique lines only)
cut
What it does
Extracts sections from lines. Great for CSV.
Example
$ cut -d"," -f1 data.csvOutput
name john mary
wc
What it does
Counts lines, words, bytes. Use -l for lines only.
Example
$ wc -l app.logOutput
1247 app.log
diff
What it does
Compares files line by line.
Example
$ diff file1.txt file2.txtOutput
< old line > new line
tr
What it does
Translates or deletes characters.
Example
$ echo "hello" | tr [:lower:] [:upper:]Output
HELLO
column
What it does
Formats input into columns.
Example
$ column -t -s"," data.csvOutput
name age city john 25 NY
tee
What it does
Reads stdin and writes to stdout AND files.
Example
$ echo "log" | tee -a log.txtOutput
log (also appends to log.txt)
tar
What it does
Archives files. -c create, -x extract, -z gzip, -v verbose.
Example
$ tar -czf backup.tar.gz /home/userOutput
(creates archive)
gzip
What it does
Compresses files using gzip algorithm.
Example
$ gzip largefile.txtOutput
(creates largefile.txt.gz)
gunzip
What it does
Decompresses gzip files.
Example
$ gunzip file.txt.gzOutput
(extracts to file.txt)
zip
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
What it does
Extracts ZIP archives. Use -l to list contents.
Example
$ unzip archive.zipOutput
inflating: file1.txt inflating: file2.txt
bzip2
What it does
Compresses using bzip2 (better compression than gzip).
Example
$ bzip2 largefile.txtOutput
(creates largefile.txt.bz2)
xz
What it does
Compresses using LZMA (best compression).
Example
$ xz largefile.txtOutput
(creates largefile.txt.xz)
7z
What it does
7-Zip archiver with high compression. Install separately.
Example
$ 7z a archive.7z folder/Output
Everything is Ok
df
What it does
Shows disk space usage for filesystems. Use -h for readable.
Example
$ df -hOutput
Filesystem Size Used Avail Use% /dev/sda1 50G 35G 13G 74%
du
What it does
Estimates file/directory space usage.
Example
$ du -sh /var/logOutput
2.3G /var/log
fdisk
What it does
Partition table manipulator. Use -l to list.
Example
$ fdisk -lOutput
Disk /dev/sda: 50 GiB
mount
What it does
Mounts filesystems.
Example
$ mount /dev/sdb1 /mntOutput
(mounts device)
umount
What it does
Unmounts filesystems.
Example
$ umount /mntOutput
(unmounts device)
lsblk
What it does
Lists block devices (disks, partitions).
Example
$ lsblkOutput
sda 8:0 0 50G 0 disk ├─sda1 8:1 0 49G 0 part /
blkid
What it does
Shows block device attributes (UUID, type).
Example
$ blkidOutput
/dev/sda1: UUID="abc-123" TYPE="ext4"
useradd
What it does
Creates new user. Use -m for home dir, -s for shell.
Example
$ useradd -m -s /bin/bash johnOutput
(creates user)
usermod
What it does
Modifies user account. Use -aG to add to groups.
Example
$ usermod -aG docker johnOutput
(adds user to docker group)
userdel
What it does
Deletes user. Use -r to remove home directory.
Example
$ userdel -r johnOutput
(deletes user and home)
groupadd
What it does
Creates new group.
Example
$ groupadd developersOutput
(creates group)
groupdel
What it does
Deletes group.
Example
$ groupdel developersOutput
(deletes group)
id
What it does
Prints user and group IDs.
Example
$ id johnOutput
uid=1001(john) gid=1001(john) groups=1001(john),27(sudo)
last
What it does
Shows last logged in users.
Example
$ lastOutput
john pts/0 192.168.1.50 Sat Jan 11 14:30 - 15:00
apt
What it does
Debian package manager. update/install/remove packages.
Example
$ sudo apt update && sudo apt upgradeOutput
Reading package lists... Done Upgrading 42 packages
apt-get
What it does
Older Debian package manager. Still widely used.
Example
$ sudo apt-get install nginxOutput
Setting up nginx... Done.
apt-cache
What it does
Searches apt package database.
Example
$ apt-cache search pythonOutput
python3 - Interactive high-level language
dpkg
What it does
Low-level Debian package tool.
Example
$ dpkg -l | grep nginxOutput
ii nginx 1.18.0 high performance web server
yum
What it does
Red Hat package manager.
Example
$ sudo yum install nginxOutput
Installing nginx... Complete!
dnf
What it does
Modern Red Hat package manager (replaces yum).
Example
$ sudo dnf install nginxOutput
Installing nginx... Complete!
snap
What it does
Universal Linux package manager.
Example
$ snap install code --classicOutput
code installed
flatpak
What it does
Cross-distro app distribution system.
Example
$ flatpak install flathub org.gimp.GIMPOutput
Installing GIMP... Done.
💡 Pro Tip
Most commands support --help flag to display usage information.
Example: ls --help
LLM Cost Calculator
Compare AI model pricing across GPT-4, Claude, Deepseek, Gemini. Calculate API costs for your usage.
PDF Tools
Merge, split, and compress PDF files entirely in your browser with complete privacy. All-in-one PDF toolkit.
Font Generator
Generate stylish fonts for social media with Unicode transformations and decorative text styles.
What Is My IP
Find your public IP address and get detailed geolocation information and network details.