Mỗi lần bạn click chuột để làm điều gì đó mà có thể gõ lệnh, bạn đang lãng phí thời gian. Terminal không chỉ nhanh hơn GUI — nó còn có thể được scripted, tự động hóa, và kết hợp theo những cách không thể làm với GUI.
Navigation Cơ Bản
pwd # In thư mục hiện tại
cd ~/projects/blog # Di chuyển đến thư mục
cd - # Quay lại thư mục trước đó
ls -la # List files, bao gồm hidden files
tree -L 2 # Hiển thị cấu trúc thư mục 2 cấp
File Operations
cp -r source/ dest/ # Copy thư mục đệ quy
mv old.py new.py # Rename/move file
rm -rf dir/ # Xóa thư mục (cẩn thận!)
ln -s /path/file link # Tạo symbolic link
chmod 755 script.sh # Phân quyền file
Text Processing Tam Giác Vàng: grep, awk, sed
# grep — tìm kiếm text
grep -r "def process" . # Tìm trong tất cả files
grep -n "import" views.py # Hiện số dòng
grep -v "DEBUG" settings.py # Exclude pattern
# sed — stream editor
sed 's/localhost/production/g' settings.py # Replace text
sed -n '10,20p' file.py # In dòng 10-20
# awk — xử lý cột
awk '{print $1, $3}' access.log # In cột 1 và 3
awk -F: '{print $1}' /etc/passwd # Split theo ':'
Find — Tìm Kiếm File
# Tìm file theo tên
find . -name "*.py" -type f
# Tìm file thay đổi trong 24 giờ
find . -mtime -1
# Tìm và xóa file .pyc
find . -name "*.pyc" -delete
# Tìm file lớn hơn 100MB
find / -size +100M -type f 2>/dev/null
Networking
# curl — HTTP requests
curl -X GET https://api.example.com/posts
curl -X POST -H "Content-Type: application/json" -d '{"title": "Test"}' https://api.example.com/posts
# wget — download file
wget -O output.zip https://example.com/file.zip
# netstat/ss — xem connections
ss -tlnp # TCP listening ports
lsof -i :8000 # Process dùng port 8000
Process Management
ps aux | grep python # Tìm process Python
kill -9 PID # Force kill process
htop # Interactive process viewer
# Chạy background
nohup python manage.py runserver &
jobs # List background jobs
fg %1 # Bring job 1 to foreground
SSH Và Remote
ssh user@server.com # Kết nối SSH
ssh-copy-id user@server.com # Copy SSH key
scp file.py user@server:/app/ # Copy file lên server
rsync -avz src/ user@server:/dest/ # Sync thư mục
Disk và Memory
df -h # Disk usage theo partition
du -sh */ # Size của từng thư mục
free -h # RAM usage
iostat # Disk I/O statistics
Pipe Và Redirection — Sức Mạnh Thực Sự
# Đếm số dòng code Python
find . -name "*.py" | xargs wc -l | sort -n
# Top 10 IPs trong access log
awk '{print $1}' access.log | sort | uniq -c | sort -rn | head -10
# Tìm và kill process
kill $(lsof -t -i:8000)
# Monitor log file real-time
tail -f /var/log/nginx/access.log | grep "ERROR"
Terminal fluency là kỹ năng có compound returns — mỗi lệnh mới bạn học sẽ kết hợp được với những lệnh cũ, tạo ra khả năng ngày càng mạnh hơn.
Kết Luận
Đừng cố nhớ tất cả cùng một lúc. Hãy bắt đầu với grep, find, và curl — ba lệnh có ích nhất cho web developer. Dần dần thêm các lệnh khác vào khi gặp nhu cầu thực tế. Sau vài tháng, bạn sẽ ngạc nhiên khi nhìn lại bao nhiêu thứ mình đã làm được từ terminal.
Chưa có bình luận. Hãy là người đầu tiên!