Complete Unix Command Guide
Complete Unix Command Reference
1. DIRECTORY & FILE NAVIGATION
------------------------------
pwd - Print current directory
cd /path - Change to directory
cd .. - Go to parent directory
cd - - Go to previous directory
ls - List files
ls -al - List all files with details
2. FILE OPERATIONS
------------------
touch file.txt - Create file
cp file1 file2 - Copy file
cp -r dir1 dir2 - Copy directory
mv old new - Move or rename
rm file - Delete file
rm -rf dir - Delete folder recursively
mkdir folder - Create directory
rmdir folder - Delete empty directory
3. VIEWING FILE CONTENT
------------------------
cat file - Show content
less file - View content page-wise
more file - Similar to less
head file - First 10 lines
tail file - Last 10 lines
tail -f file - Monitor live updates
4. FILE PERMISSIONS
-------------------
chmod 755 file - rwxr-xr-x permission
chmod u+x file - Add execute to user
chown user:group file - Change owner
ls -l - View permissions
5. FINDING FILES
----------------
find /path -name "*.log" - Find .log files
find . -type f -mtime -1 - Modified in last 1 day
find . -size +100M - Larger than 100MB
locate filename - Locate quickly
6. TEXT SEARCHING
-----------------
grep "text" file - Search text
Complete Unix Command Guide
grep -i "text" - Case-insensitive
grep -r "text" dir - Recursive search
grep -v "text" - Exclude text
grep -A 3 -B 2 "fail" - Contextual lines
7. DISK USAGE
-------------
df -h - Disk usage
du -sh * - Size of files/folders
du -ah | sort -rh | head -10 - Top 10 biggest
8. PROCESS MANAGEMENT
---------------------
ps -ef - List processes
top - Live usage
kill PID - Kill process
kill -9 PID - Force kill
jobs, bg, fg - Job control
9. NETWORKING
-------------
ping host - Ping test
netstat -tulnp - Open ports
curl URL - Fetch data
wget URL - Download
scp file user@host:/path - Copy to remote
ssh user@host - SSH login
10. ARCHIVE & COMPRESS
----------------------
tar -cvf file.tar dir - Create archive
tar -xvf file.tar - Extract
tar -czvf file.tar.gz dir - Gzip tar
gzip/gunzip file - Compress/decompress
zip/unzip file - Zip/unzip
11. CRONTAB
-----------
crontab -l - List jobs
crontab -e - Edit cron jobs
crontab -r - Remove jobs
Syntax: * * * * * /command.sh
12. SYSTEM INFO
---------------
uname -a - System info
uptime - How long running
whoami - Current user
hostname - Hostname
Complete Unix Command Guide
date - Current date/time
cal - Calendar
13. ADVANCED TEXT TOOLS
------------------------
AWK:
awk '{print $1, $3}' file.txt
awk -F ',' '{print $2}' file.csv
SED:
sed 's/old/new/g' file.txt
sed -n '5,10p' file.txt
14. SHELL SCRIPTING BASICS
---------------------------
#!/bin/bash
echo "Hello, $USER"
now=$(date)
echo "Current time: $now"
Loops:
for i in {1..5}; do echo "Number: $i"; done
If:
if [ -f /etc/passwd ]; then echo "Exists"; fi