A comprehensive guide to essential Linux commands for beginners and experienced users alike. These commands are organized by category to help you find what you need quickly.
ls -la
List all files (including hidden) in long format with details
ls -lh
List files with human-readable sizes
cp file.txt backup/
Copy file.txt to the backup directory
cp -r dir1/ dir2/
Copy directory dir1 and its contents to dir2 recursively
mv file.txt newname.txt
Rename file.txt to newname.txt
mv file.txt ~/Documents/
Move file.txt to the Documents directory
rm file.txt
Delete file.txt
rm -rf directory/
Delete directory and its contents forcefully
touch newfile.txt
Create a new empty file named newfile.txt
touch -a file.txt
Update only the access time of file.txt
cat file.txt
Display contents of file.txt
cat file1.txt file2.txt > combined.txt
Combine two files into one
head -n 10 file.txt
Show first 10 lines of file
tail -f /var/log/syslog
Follow log file in real-time
less large_file.txt
View large file with pagination
nano newfile.txt
Create or edit a text file
vim script.sh
Edit a shell script
mkdir newfolder
Create a directory named newfolder
mkdir -p parent/child/grandchild
Create nested directories including any necessary parent directories
cd /home/user/documents
Change to the documents directory
cd ..
Move up one directory level
cd ~
Go to home directory
rmdir emptyfolder
Remove the directory named emptyfolder (if empty)
rmdir -p parent/child/grandchild
Remove nested directories if empty
uname -a
Print all system information
uname -r
Print the kernel release
date
Show current date and time
date +"%Y-%m-%d"
Display date in YYYY-MM-DD format
free -h
Show memory usage in human readable format
uptime
Display system uptime and load
lsof -i :80
Show processes using port 80
dmesg | grep error
Show kernel error messages
ps aux
Display all running processes in BSD format
ps -ef
Display all running processes in standard format
kill 1234
Terminate process with PID 1234
kill -9 1234
Force kill process with PID 1234
top
Show real-time process activity
top -u username
Show processes for a specific user
htop
Launch interactive process viewer
nice -n 10 ./script.sh
Run script with lower priority
renice -n 5 -p 1234
Change priority of process ID 1234
whoami
Print the current user's username
passwd
Change your own password
sudo passwd username
Change another user's password (as root)
useradd -m username
Create user with home directory
userdel -r username
Delete user and their home directory
usermod -aG sudo username
Add user to sudo group
sudo apt update
Update package lists
sudo apt install package_name
Install a package
sudo yum update
Update all packages
sudo yum install package_name
Install a package
chmod 755 file.sh
Give read, write, execute to owner; read, execute to group and others
chmod +x script.sh
Add execute permission for all users
sudo chown user1 file.txt
Change the owner of file.txt to user1
sudo chown -R user1:group1 directory/
Change owner and group of directory and its contents recursively
find /home -name "*.txt"
Find all .txt files in /home directory
find . -type f -mtime -7
Find files modified in the last 7 days
grep "search term" file.txt
Search for "search term" in file.txt
grep -r "search term" directory/
Search recursively through directory
tar -cvf archive.tar files/
Create a tar archive of files/ directory
tar -xvf archive.tar
Extract a tar archive
gzip file.txt
Compress file.txt (creates file.txt.gz)
gzip -d file.txt.gz
Decompress file.txt.gz
ping google.com
Ping google.com continuously
ping -c 4 8.8.8.8
Ping Google's DNS server 4 times
ifconfig
Display information for all interfaces
ifconfig eth0
Display information for eth0 interface
nslookup google.com
Look up DNS information for google.com
dig +short example.com
Get IP address for domain
traceroute google.com
Show route to google.com
df -h
Show disk space in human-readable format
df -i
Show inode information
du -sh directory/
Show total size of directory in human-readable format
du -h --max-depth=1
Show sizes of immediate subdirectories
sudo fdisk -l
List all disk partitions
mount /dev/sdb1 /mnt
Mount device to directory
umount /mnt
Unmount filesystem at /mnt
sudo apt update
Run apt update as root
sudo -u username command
Run command as the specified user
sudo systemctl start service-name
Start a service
sudo systemctl status service-name
Check the status of a service
locate *.jpg
Find all .jpg files in database
which python3
Find path to python3 executable
whereis bash
Find bash binary and manual locations
zip -r archive.zip folder/
Create zip archive of folder
unzip archive.zip
Extract zip archive
bzip2 large_file
Compress file using bzip2
hostname
Display current hostname
history | grep ssh
Show SSH-related commands from history
alias ll='ls -la'
Create alias for detailed list
nohup ./script.sh &
Run script in background, immune to hangups
jobs -l
List jobs with process IDs
bg %1
Resume job 1 in background
fg %2
Bring job 2 to foreground
nc -l 1234
Listen on port 1234
tcpdump -i eth0
Capture packets on eth0 interface
iptables -L
List all firewall rules
mkfs.ext4 /dev/sdb1
Create ext4 filesystem
fsck /dev/sda1
Check filesystem for errors
lsblk -f
Show filesystem information
service apache2 restart
Restart Apache web server
journalctl -u nginx.service
Show Nginx service logs
chroot /mnt/newroot /bin/bash
Start shell with new root directory
crontab -e
Edit your cron jobs
at 2:30pm
Schedule command execution for 2:30 PM
ln -s target link
Create symbolic link
file image.jpg
Show file type information
stat file.txt
Show detailed file information
rsync -av source/ dest/
Synchronize directories
telnet localhost 80
Connect to local web server
awk '{print $1}' file.txt
Print first field of each line
sed 's/old/new/g' file.txt
Replace text in file
watch -n 1 free -m
Monitor memory usage every second
time ls -R /
Measure execution time of command
echo "test" | tee file.txt
Write output to file and screen
w
Display information about logged-in users
last -n 5
Show last 5 logins
who -H
Show header line
dd if=/dev/zero of=file.txt count=1 bs=1M
Create a 1MB file filled with zeros
sort -n numbers.txt
Sort numbers numerically
sort file.txt | uniq -c
Count occurrences of lines
route -n
Show routing table in numeric form
host google.com
Look up DNS records for google.com
pgrep -l nginx
Find and list nginx processes
pkill -9 firefox
Force kill all firefox processes
strace ls
Show system calls made by ls command
wc -l file.txt
Count lines in file
diff file1.txt file2.txt
Show differences between two files
patch < patchfile.diff
Apply patch to files
logger "System backup completed"
Log a message to syslog