A quick reference for common Linux commands and tools frequently used for Linux.
| Command |
Description |
Example |
Important Flags |
pwd |
Print working directory |
pwd |
– |
cd |
Change directory |
cd /etc |
- (previous directory) |
ls |
List directory contents |
ls -l |
-l (long), -a (all), -h (human readable) |
tree |
Display directories as tree structure |
tree /var |
-L (depth) |
stat |
Show detailed file info |
stat file.txt |
– |
| Command |
Description |
Example |
Important Flags |
cp |
Copy files or directories |
cp file1.txt /tmp/ |
-r (recursive), -p (preserve) |
mv |
Move or rename files |
mv file.txt /tmp/ |
– |
rm |
Remove files or directories |
rm file.txt |
-r (recursive), -f (force) |
touch |
Create empty file / update timestamp |
touch new.txt |
– |
mkdir |
Create directories |
mkdir /opt/test |
-p (parents) |
rmdir |
Remove empty directories |
rmdir emptydir |
– |
| Command |
Description |
Example |
Important Flags |
cat |
Concatenate and display files |
cat file.txt |
– |
less |
View file contents page by page |
less /var/log/syslog |
/ (search), q (quit) |
head |
Show first lines of a file |
head -n 20 file.txt |
-n (number of lines) |
tail |
Show last lines of a file |
tail -f /var/log/syslog |
-f (follow) |
nano |
Terminal text editor |
nano file.txt |
– |
vim |
Advanced terminal text editor |
vim file.txt |
– |
| Command |
Description |
Example |
Important Flags |
find |
Search files/directories by criteria |
find / -name "*.conf" |
-type, -size, -mtime |
locate |
Quick file search using database |
locate passwd |
– |
grep |
Search text in files |
grep "error" /var/log/syslog |
-i (ignore case), -r (recursive) |
egrep |
Extended grep (regex) |
egrep 'error|fail' logfile |
– |
which |
Locate executable |
which python3 |
– |
whereis |
Show binary, source, and man path |
whereis ls |
– |
| Command |
Description |
Example |
Important Flags |
chmod |
Change permissions |
chmod 755 script.sh |
-R (recursive) |
chown |
Change owner and/or group |
chown user:group file.txt |
-R (recursive) |
chgrp |
Change group ownership |
chgrp developers file.txt |
– |
umask |
Set default file permissions mask |
umask 022 |
– |
| Command |
Description |
Example |
Important Flags |
df |
Show disk space usage |
df -h |
-h (human readable) |
du |
Show directory/file space usage |
du -sh /var/log |
-s, -h |
mount |
Mount filesystem |
mount /dev/sdb1 /mnt |
– |
umount |
Unmount filesystem |
umount /mnt |
– |
lsblk |
List block devices |
lsblk |
– |
blkid |
Show block device attributes |
blkid |
– |
fsck |
Filesystem check and repair |
fsck /dev/sda1 |
– |
| Command |
Description |
Example |
Important Flags |
ip addr |
Show IP addresses |
ip addr show |
– |
ip link |
Show/manage network interfaces |
ip link set eth0 down |
– |
ping |
Test network connectivity |
ping 8.8.8.8 |
-c (count) |
curl |
Fetch content from URL |
curl https://example.com |
-O (save file) |
wget |
Download files from URL |
wget http://example.com/file |
-c (continue) |
netstat |
Show network connections |
netstat -tulnp |
– |
ss |
Socket statistics |
ss -tulnp |
– |
traceroute |
Show network path |
traceroute google.com |
– |
dig |
DNS lookup |
dig example.com |
– |
nslookup |
DNS query tool |
nslookup example.com |
– |
| Command |
Description |
Example |
Important Flags |
ps |
Show running processes |
ps aux |
– |
top |
Interactive process monitor |
top |
– |
htop |
Enhanced process viewer |
htop |
– |
kill |
Kill process by PID |
kill 1234 |
-9 (force) |
killall |
Kill by process name |
killall firefox |
– |
systemctl |
Manage systemd services |
systemctl restart nginx |
start, stop, status |
journalctl |
View systemd logs |
journalctl -xe |
-u (unit), -f (follow) |
| Command |
Description |
Example |
Important Flags |
whoami |
Show current user |
whoami |
– |
id |
Show user and group IDs |
id user |
– |
adduser |
Add a new user |
adduser alice |
– |
userdel |
Delete a user |
userdel bob |
-r (remove home dir) |
usermod |
Modify a user |
usermod -aG sudo alice |
– |
groupadd |
Add a group |
groupadd developers |
– |
groups |
Show groups for user |
groups alice |
– |
Debian/Ubuntu (APT):
| Command |
Description |
Example |
apt update |
Update package lists |
sudo apt update |
apt upgrade |
Upgrade all packages |
sudo apt upgrade |
apt install |
Install a package |
sudo apt install nginx |
apt remove |
Remove a package |
sudo apt remove nginx |
apt search |
Search package |
apt search nginx |
RHEL/CentOS (YUM/DNF):
| Command |
Description |
Example |
yum install |
Install a package |
sudo yum install httpd |
yum remove |
Remove a package |
sudo yum remove httpd |
dnf update |
Update packages |
sudo dnf update |
dnf search |
Search for packages |
dnf search nginx |
| Command |
Description |
Example |
Important Flags |
tar |
Archive files |
tar -cvf archive.tar file1 |
-z (gzip), -j (bzip2) |
gzip |
Compress file |
gzip file.txt |
– |
gunzip |
Decompress file |
gunzip file.txt.gz |
– |
zip |
Create zip archive |
zip archive.zip file1 file2 |
-r (recursive) |
unzip |
Extract zip archive |
unzip archive.zip |
– |
| Command |
Description |
Example |
Important Flags |
uname |
Show system/kernel info |
uname -a |
– |
hostname |
Show or set hostname |
hostname |
– |
uptime |
Show system uptime |
uptime |
– |
free |
Show memory usage |
free -h |
– |
lscpu |
Show CPU info |
lscpu |
– |
lsusb |
Show USB devices |
lsusb |
– |
lspci |
Show PCI devices |
lspci |
– |
Tip: Combine commands with pipes (|) and redirection (>, >>) for powerful one-liners.