Linux provides powerful command-line tools for managing files, users, processes, networking, and the system itself. This guide summarizes the most essential commands with simple examples to help you get comfortable with daily terminal workflows.
1. File & Directory Management
Basic Navigation
| Command | Description | Example |
pwd | Show current directory | pwd |
ls | List files | ls -l |
cd | Change directory | cd /etc |
Create & Remove Directories
| Command | Description | Example |
mkdir | Create directory | mkdir new_folder |
rmdir | Remove empty directory | rmdir test_dir |
File Operations
| Command | Description | Example |
rm | Remove files/directories | rm -rf temp/ |
cp | Copy files/directories | cp file.txt backup.txt |
mv | Move/rename files | mv old.txt new.txt |
touch | Create an empty file | touch test.txt |
file | Identify file type | file script.sh |
2. File Content Operations
View File Content
| Command | Description | Example |
cat | View file | cat notes.txt |
less | Paged view (scroll) | less syslog |
more | Paged view | more test.txt |
View Specific Parts
| Command | Description | Example |
head | First lines | head -n 5 file.txt |
tail | Last lines | tail -n 10 file.txt |
tail -f | Follow live updates | tail -f /var/log/syslog |
Utilities
| Command | Description | Example |
wc | Count words/lines/chars | wc -l data.txt |
sort | Sort lines | sort names.txt |
uniq | Remove duplicates | uniq sorted.txt |
cut | Extract text sections | cut -d ':' -f1 /etc/passwd |
3. Searching
| Command | Description | Example |
grep | Search in files | grep "main" app.py |
find | Locate files on system | find . -name "*.sh" |
locate | Fast file search | locate nginx.conf |
which | Show binary location | which python3 |
whereis | Find binary & source | whereis ls |
basename | Extract file name | basename /home/user/test.txt |
dirname | Extract directory path | dirname /home/user/test.txt |
xargs | Pass input as arguments | `ls | xargs` |
diff | Compare files | diff file1 file2 |
cmp | Byte-wise compare | cmp file1 file2 |
4. File Permissions & Ownership
| Command | Description | Example |
chmod | Change permissions | chmod +x script.sh |
chown | Change owner | chown user:group file.txt |
chgrp | Change group | chgrp dev file.txt |
umask | Set default permissions | umask 022 |
stat | Detailed file info | stat file.txt |
5. User Management
| Command | Description | Example |
whoami | Show current user | whoami |
id | Show UID/GID | id |
adduser | Add user (easy) | sudo adduser devops |
useradd | Add user (manual) | sudo useradd -m test |
passwd | Change password | passwd user |
usermod | Modify user | usermod -aG sudo devops |
userdel | Delete user | userdel -r test |
groupadd | Create group | groupadd admins |
groups | List groups | groups aditya |
who | Logged-in users | who |
| Command | Description | Example |
uname | System info | uname -a |
hostnamectl | Set hostname | hostnamectl set-hostname dev-server |
uptime | Uptime/load | uptime |
top | Task manager | top |
htop | Enhanced top | htop |
free | RAM info | free -h |
vmstat | System stats | vmstat |
dmesg | Kernel logs | dmesg |
lscpu | CPU details | lscpu |
lsblk | Storage devices | lsblk |
7. Disk & Filesystem
| Command | Description | Example |
df | Disk usage | df -h |
du | Directory size | du -sh * |
mount | Mount filesystem | mount /dev/sdb1 /mnt |
umount | Unmount | umount /mnt |
blkid | Disk UUID | blkid |
fdisk | Partition manager | fdisk /dev/sda |
mkfs | Format partition | mkfs.ext4 /dev/sdb1 |
tune2fs | Tune filesystem | tune2fs -l /dev/sda1 |
fsck | Disk check | fsck /dev/sda1 |
sync | Flush cache | sync |
8. Networking
9. Package Management
Debian/Ubuntu
| Command | Description | Example |
apt update | Update index | sudo apt update |
apt install | Install package | sudo apt install nginx |
apt remove | Remove package | sudo apt remove nginx |
dpkg | Manage .deb files | dpkg -i package.deb |
apt list | List installed | apt list --installed |
apt-cache | Search packages | apt-cache search apache |
snap | Snap store | snap install code |
RHEL/CentOS
| Command | Description | Example |
yum | Install package | yum install httpd |
dnf | Modern pkg manager | dnf update |
rpm | RPM package manager | rpm -ivh pkg.rpm |
10. Process Management
| Command | Description | Example |
ps aux | List processes | ps aux |
kill | Kill by PID | kill 1234 |
killall | Kill by name | killall nginx |
bg | Background process | bg |
fg | Foreground process | fg |
jobs | List jobs | jobs |
nice | Set start priority | nice -n 10 ./script.sh |
renice | Change priority | renice 10 -p 1234 |
watch | Repeat command | watch -n 2 free -h |
strace | Trace syscalls | strace ls |
11. Superuser / Admin
| Command | Description | Example |
sudo | Run as root | sudo reboot |
su | Switch user | su - |
visudo | Edit sudoers | sudo visudo |
12. Archiving & Compression
| Command | Description | Example |
tar | Archive & compress | tar -czvf backup.tar.gz folder/ |
gzip | Compress file | gzip logfile.txt |
gunzip | Decompress | gunzip logfile.txt.gz |
zip | Create zip | zip data.zip *.csv |
unzip | Extract zip | unzip data.zip |
13. Shell & Scripting
| Command | Description | Example |
echo | Print text | echo "Hello" |
read | Take input | read name |
alias | Create shortcut | alias ll='ls -la' |
export | Set environment variable | export PATH=$PATH:/opt/bin |