Essential Linux Commands List: Usage, Examples & Explanations

Command Use Case Explanation ls List directory contents Displays files and directories in the current directory. Use ls -l for detailed info. cd Change directory Navigates between directories. Example: cd /home/user moves to /home/user. pwd Print working directory Shows the current directory path. Useful to confirm location. mkdir Create a directory Example: mkdir new_folder creates a new folder named new_folder. rmdir Remove empty directory Deletes an empty directory. Use rm -r for non-empty ones. rm Remove files or directories Deletes files (rm file.txt) or directories (rm -r folder). cp Copy files and directories Example: cp file.txt /backup/ copies file.txt to /backup/. mv Move or rename files Example: mv old.txt new.txt renames old.txt to new.txt. cat View file contents Displays file content. Example: cat file.txt. less View large files Scroll through large files page by page. Example: less log.txt. head View first lines of a file Example: head -n 10 file.txt shows the first 10 lines. tail View last lines of a file Example: tail -n 10 file.txt shows the last 10 lines. grep Search in files Example: grep 'error' log.txt searches for 'error' in log.txt. find Search for files Example: find /home -name '*.txt' finds all .txt files. locate Find files quickly Uses a prebuilt index. Example: locate file.txt. du Disk usage Example: du -sh folder/ shows folder size. df Disk space usage Example: df -h shows available disk space in human-readable format. chmod Change file permissions Example: chmod 755 script.sh sets executable permissions. chown Change file owner Example: chown user:group file.txt assigns a new owner. ps List running processes Example: ps aux shows all running processes. top Display system usage Shows CPU/memory usage and running processes. htop Interactive process viewer A better version of top (requires installation). kill Terminate a process Example: kill 1234 stops the process with PID 1234. pkill Kill process by name Example: pkill firefox terminates all firefox processes. tar Archive files Example: tar -czvf archive.tar.gz folder/ creates a compressed archive. unzip Extract ZIP files Example: unzip archive.zip. gzip Compress files Example: gzip file.txt compresses file.txt to file.txt.gz. gunzip Decompress GZIP files Example: gunzip file.txt.gz restores file.txt. ssh Secure shell connection Example: ssh user@server.com connects to a remote server. scp Secure copy over SSH Example: scp file.txt user@server:/backup/. rsync Sync files and directories Example: rsync -av source/ destination/. wget Download files Example: wget https://example.com/file.zip. curl Transfer data from URLs Example: curl -O https://example.com/file.zip. nano Edit text files Example: nano file.txt opens file.txt for editing. vim Advanced text editor Example: vim file.txt. Press i to edit, Esc to exit insert mode, :wq to save and quit. history Show command history Lists previously executed commands. clear Clear terminal screen Clears the command line screen. echo Print text to terminal Example: echo "Hello, World!". export Set environment variables Example: export PATH=$PATH:/new/path. alias Create command shortcuts Example: alias ll='ls -la' defines ll as ls -la. uptime Show system uptime Displays how long the system has been running. uname Show system information Example: uname -a displays kernel version and system details. whoami Show current user Displays the currently logged-in username. id Show user ID and group Example: id username. groups Show group memberships Lists the groups a user belongs to. passwd Change user password Example: passwd username. shutdown Power off system Example: shutdown -h now shuts down immediately. reboot Restart system Example: reboot. cron Schedule tasks Example: crontab -e opens the crontab file for scheduling tasks. systemctl Manage services Example: systemctl restart apache2 restarts Apache. journalctl View logs Example: journalctl -u apache2 shows logs for Apache. dmesg View boot logs Example: `dmesg {% raw %}ip Show network details Example: ip a displays network interfaces. ping Test network connectivity Example: ping google.com. traceroute Trace network path Example: traceroute google.com. netstat Show network connections Example: netstat -tulnp. ss Display active connections Example: ss -tulnp (alternative to netstat). nslookup Query DNS records Example: nslookup google.com. dig Get DNS info Example: dig google.com. iptables Manage firewall rules Example: iptables -L lists rules. ufw Simplified firewall Example: ufw allow 22/tcp allows SSH traffic. mount Mount file systems Example: mount /dev/sdb1 /mnt/usb. umount Unmount file systems Example: umount /mnt/usb. df Show disk usage Example: df -h. fsck Check and repair file system Example: fsck /dev/sda1. mkfs Format a filesystem Example: mkfs.ext4 /dev/sdb1. tune2fs Adjust ext4 filesystem setti

Mar 13, 2025 - 02:17
 0
Essential Linux Commands List: Usage, Examples & Explanations
Command Use Case Explanation
ls List directory contents Displays files and directories in the current directory. Use ls -l for detailed info.
cd Change directory Navigates between directories. Example: cd /home/user moves to /home/user.
pwd Print working directory Shows the current directory path. Useful to confirm location.
mkdir Create a directory Example: mkdir new_folder creates a new folder named new_folder.
rmdir Remove empty directory Deletes an empty directory. Use rm -r for non-empty ones.
rm Remove files or directories Deletes files (rm file.txt) or directories (rm -r folder).
cp Copy files and directories Example: cp file.txt /backup/ copies file.txt to /backup/.
mv Move or rename files Example: mv old.txt new.txt renames old.txt to new.txt.
cat View file contents Displays file content. Example: cat file.txt.
less View large files Scroll through large files page by page. Example: less log.txt.
head View first lines of a file Example: head -n 10 file.txt shows the first 10 lines.
tail View last lines of a file Example: tail -n 10 file.txt shows the last 10 lines.
grep Search in files Example: grep 'error' log.txt searches for 'error' in log.txt.
find Search for files Example: find /home -name '*.txt' finds all .txt files.
locate Find files quickly Uses a prebuilt index. Example: locate file.txt.
du Disk usage Example: du -sh folder/ shows folder size.
df Disk space usage Example: df -h shows available disk space in human-readable format.
chmod Change file permissions Example: chmod 755 script.sh sets executable permissions.
chown Change file owner Example: chown user:group file.txt assigns a new owner.
ps List running processes Example: ps aux shows all running processes.
top Display system usage Shows CPU/memory usage and running processes.
htop Interactive process viewer A better version of top (requires installation).
kill Terminate a process Example: kill 1234 stops the process with PID 1234.
pkill Kill process by name Example: pkill firefox terminates all firefox processes.
tar Archive files Example: tar -czvf archive.tar.gz folder/ creates a compressed archive.
unzip Extract ZIP files Example: unzip archive.zip.
gzip Compress files Example: gzip file.txt compresses file.txt to file.txt.gz.
gunzip Decompress GZIP files Example: gunzip file.txt.gz restores file.txt.
ssh Secure shell connection Example: ssh user@server.com connects to a remote server.
scp Secure copy over SSH Example: scp file.txt user@server:/backup/.
rsync Sync files and directories Example: rsync -av source/ destination/.
wget Download files Example: wget https://example.com/file.zip.
curl Transfer data from URLs Example: curl -O https://example.com/file.zip.
nano Edit text files Example: nano file.txt opens file.txt for editing.
vim Advanced text editor Example: vim file.txt. Press i to edit, Esc to exit insert mode, :wq to save and quit.
history Show command history Lists previously executed commands.
clear Clear terminal screen Clears the command line screen.
echo Print text to terminal Example: echo "Hello, World!".
export Set environment variables Example: export PATH=$PATH:/new/path.
alias Create command shortcuts Example: alias ll='ls -la' defines ll as ls -la.
uptime Show system uptime Displays how long the system has been running.
uname Show system information Example: uname -a displays kernel version and system details.
whoami Show current user Displays the currently logged-in username.
id Show user ID and group Example: id username.
groups Show group memberships Lists the groups a user belongs to.
passwd Change user password Example: passwd username.
shutdown Power off system Example: shutdown -h now shuts down immediately.
reboot Restart system Example: reboot.
cron Schedule tasks Example: crontab -e opens the crontab file for scheduling tasks.
systemctl Manage services Example: systemctl restart apache2 restarts Apache.
journalctl View logs Example: journalctl -u apache2 shows logs for Apache.
dmesg View boot logs Example: `dmesg
{% raw %}ip Show network details Example: ip a displays network interfaces.
ping Test network connectivity Example: ping google.com.
traceroute Trace network path Example: traceroute google.com.
netstat Show network connections Example: netstat -tulnp.
ss Display active connections Example: ss -tulnp (alternative to netstat).
nslookup Query DNS records Example: nslookup google.com.
dig Get DNS info Example: dig google.com.
iptables Manage firewall rules Example: iptables -L lists rules.
ufw Simplified firewall Example: ufw allow 22/tcp allows SSH traffic.
mount Mount file systems Example: mount /dev/sdb1 /mnt/usb.
umount Unmount file systems Example: umount /mnt/usb.
df Show disk usage Example: df -h.
fsck Check and repair file system Example: fsck /dev/sda1.
mkfs Format a filesystem Example: mkfs.ext4 /dev/sdb1.
tune2fs Adjust ext4 filesystem settings Example: tune2fs -c 30 /dev/sda1.
iostat Show CPU and disk I/O usage Example: iostat.
vmstat Show system performance Example: vmstat 5.
mpstat Show CPU usage Example: mpstat -P ALL.
sar Monitor system performance Example: sar -u 5 10.

This list covers essential Linux commands for daily use.