Extended Linux Commands with
Examples
1. File and Directory Commands
ls: Lists detailed contents of /home directory
Usage: ls -l /home
cd: Changes current directory to /var/log
Usage: cd /var/log
pwd: Displays the current directory path
Usage: pwd
mkdir: Creates a directory named projects
Usage: mkdir projects
rmdir: Removes the directory old_folder if empty
Usage: rmdir old_folder
rm: Force deletes the temp directory and its contents
Usage: rm -rf temp
touch: Creates an empty file named file.txt
Usage: touch file.txt
cp: Copies file.txt to backup.txt
Usage: cp file.txt backup.txt
mv: Moves data.csv to archive directory
Usage: mv data.csv archive/
cat: Displays the content of notes.txt
Usage: cat notes.txt
more: Views long files page-by-page
Usage: more longfile.txt
less: Views content with navigation
Usage: less config.log
head: Displays the first 5 lines of file.txt
Usage: head -n 5 file.txt
tail: Displays the last 10 lines of file.txt
Usage: tail -n 10 file.txt
find: Searches for all .sh files in /home
Usage: find /home -name "*.sh"
grep: Finds lines with 'root' in /etc/passwd
Usage: grep 'root' /etc/passwd
file: Shows the type of image.png
Usage: file image.png
basename: Extracts the filename 'bash'
Usage: basename /usr/bin/bash
dirname: Extracts the path '/usr/bin'
Usage: dirname /usr/bin/bash
2. Disk and Partition Commands
df: Shows human-readable disk usage
Usage: df -h
du: Displays size of files/folders in current dir
Usage: du -sh *
mount: Mounts sdb1 to /mnt/usb
Usage: mount /dev/sdb1 /mnt/usb
umount: Unmounts the USB drive
Usage: umount /mnt/usb
lsblk: Lists block devices and mount points
Usage: lsblk
blkid: Displays UUID and file system type of devices
Usage: blkid
fdisk: Lists all available partitions
Usage: sudo fdisk -l
mkfs: Formats /dev/sdb1 with ext4
Usage: mkfs.ext4 /dev/sdb1
tune2fs: Shows file system parameters
Usage: tune2fs -l /dev/sda1
e2label: Labels the partition as 'data'
Usage: e2label /dev/sda1 data
3. Network Commands
ping: Sends 4 ping packets to google.com
Usage: ping -c 4 google.com
ip a: Shows IP addresses of all interfaces
Usage: ip a
ifconfig: Displays configuration of eth0
Usage: ifconfig eth0
netstat: Lists open ports and listening services
Usage: netstat -tulnp
ss: Shows socket stats like netstat
Usage: ss -tulwn
curl: Fetches web page HTML
Usage: curl https://example.com
wget: Downloads file.zip
Usage: wget https://file.com/file.zip
scp: Copies file to remote machine
rsync: Synchronizes source to backup
Usage: rsync -av source/ backup/
ssh: Connects to host via SSH
Usage: ssh user@host
hostname: Displays the system hostname
Usage: hostname
dig: Performs DNS lookup for google.com
Usage: dig google.com
nslookup: Queries DNS for example.com
Usage: nslookup example.com
traceroute: Traces route to google.com
Usage: traceroute google.com
nmap: Scans open TCP ports on 192.168.1.1
Usage: nmap -sT 192.168.1.1
4. System and Process Commands
top: Displays real-time system resource usage
Usage: top
htop: Interactive process viewer
Usage: htop
ps: Lists Apache processes
Usage: ps aux | grep apache
kill: Sends SIGTERM to process ID 1234
Usage: kill 1234
killall: Kills all Firefox processes
Usage: killall firefox
shutdown: Shuts down system immediately
Usage: shutdown -h now
reboot: Reboots the system
Usage: reboot
uptime: Shows how long the system has been running
Usage: uptime
whoami: Displays the current user
Usage: whoami
id: Displays UID and GID of user
Usage: id user
free: Displays memory usage in human-readable format
Usage: free -h
vmstat: Displays system performance every second
Usage: vmstat 1
dmesg: Views kernel messages
Usage: dmesg | less
uname -a: Displays kernel and system information
Usage: uname -a
5. Package Management (Debian-based)
apt update: Refreshes package database
Usage: sudo apt update
apt upgrade: Installs available upgrades
Usage: sudo apt upgrade
apt install: Installs htop
Usage: sudo apt install htop
apt remove: Uninstalls nano
Usage: sudo apt remove nano
apt purge: Removes nginx with config files
Usage: sudo apt purge nginx
apt autoremove: Removes unnecessary dependencies
Usage: sudo apt autoremove
dpkg -i: Installs local .deb package
Usage: sudo dpkg -i package.deb
dpkg -r: Removes a package
Usage: sudo dpkg -r package_name
dpkg -l: Lists installed SSH-related packages
Usage: dpkg -l | grep ssh
6. User Management
adduser: Creates a user john
Usage: sudo adduser john
passwd: Sets or changes password for john
Usage: sudo passwd john
deluser: Deletes user john
Usage: sudo deluser john
usermod: Adds john to sudo group
Usage: sudo usermod -aG sudo john
groupadd: Creates a group named devs
Usage: sudo groupadd devs
groups: Lists groups john belongs to
Usage: groups john
7. Compression and Archiving
tar: Creates gzipped archive of folder
Usage: tar -czvf archive.tar.gz folder
gzip: Compresses file.txt to file.txt.gz
Usage: gzip file.txt
gunzip: Decompresses .gz file
Usage: gunzip file.txt.gz
zip: Creates a zip file
Usage: zip archive.zip file.txt
unzip: Extracts a zip archive
Usage: unzip archive.zip
8. Miscellaneous Tools
alias: Creates a shortcut command for listing
Usage: alias ll='ls -alF'
history: Searches shell history for ssh
Usage: history | grep ssh
date: Displays current date in format
Usage: date '+%Y-%m-%d'
cal: Displays calendar for 2025
Usage: cal 2025
uptime: Shows how long system has been running
Usage: uptime
bc: Performs simple math in terminal
Usage: echo '2+3' | bc