บทความ Linux Command Line 50
เผยแพร่ 28 พฤษภาคม 2569
ทำไม Linux Command Line ถึงสำคัญในปี 2026?
Linux เป็นระบบปฏิบัติการที่ขับเคลื่อน server มากกว่า 96% ของ top 1 ล้านเว็บไซต์ในโลกทั้ง AWS, Azure, GCP ใช้ Linux เป็นหลัก Docker, Kubernetes ทำงานบน Linux ดังนั้น ทักษะ Linux Command Line คือพื้นฐานที่คน IT ทุกู้คืนต้องมี
บทความนี้รวบรวม 50 commands ที่ใช้บ่อยที่สุดในงาน IT จริงพร้อมตัวอย่างและคำอธิบาย
คำสั่งจัดการไฟล์และไดเรกทอรี (File Management)
| # | Command | หน้าที่ | ตัวอย่าง |
| 1 | ls | แสดงรายการไฟล์ | ls -lah แสดงทั้งหมดพร้อมขนาด |
| 2 | cd | เปลี่ยน directory | cd /var/log |
| 3 | pwd | แสดง directory ปัจจุบัน | pwd → /home/user |
| 4 | mkdir | สร้าง directory | mkdir -p app/{src, config, logs} |
| 5 | rm | ลบไฟล์/directory | rm -rf old_backup/ (ระวัง!) |
| 6 | cp | คัดลอกไฟล์ | cp -r src/ dest/ |
| 7 | mv | ย้าย/เปลี่ยนชื่อ | mv old.txt new.txt |
| 8 | find | ค้นหาไฟล์ | find / -name "*.log" -mtime +30 |
| 9 | tree | แสดง directory tree | tree -L 2 /etc |
| 10 | du | ดูขนาด directory | du -sh /var/log/* |
คำสั่งดูและแก้ไขไฟล์ (File Viewing & Editing)
| # | Command | หน้าที่ | ตัวอย่าง |
| 11 | cat | แสดงเนื้อหาไฟล์ | cat /etc/hostname |
| 12 | less | อ่านไฟล์แบบ scroll | less /var/log/syslog |
| 13 | head | ดู 10 บรรทัดแรก | head -20 access.log |
| 14 | tail | ดู 10 บรรทัดท้าย | tail -f /var/log/nginx/error.log |
| 15 | grep | ค้นหาข้อความ | grep -r "error" /var/log/ --include="*.log" |
| 16 | awk | ประมวลผลข้อความ | awk '{print $1}' access.log | sort | uniq -c | sort -rn |
| 17 | sed | แก้ไขข้อความ | sed -i 's/old/new/g' config.txt |
| 18 | nano | text editor ง่ายๆ | nano /etc/nginx/nginx.conf |
| 19 | vim | text editor ขั้นสูง | vim /etc/ssh/sshd_config |
| 20 | wc | นับบรรทัด/คำ | wc -l access.log |
คำสั่ง Network (Networking)
| # | Command | หน้าที่ | ตัวอย่าง |
| 21 | ip addr | ดู IP address | ip addr show eth0 |
| 22 | ping | ทดสอบเชื่อมต่อ | ping -c 4 google.com |
| 23 | curl | HTTP request | curl -I https://example.com |
| 24 | wget | ดาวน์โหลดไฟล์ | wget https://example.com/file.tar.gz |
| 25 | ss | ดู open ports | ss -tulnp (แทน netstat) |
| 26 | dig | ตรวจ DNS | dig +short A example.com |
| 27 | traceroute | ดูเส้นทาง network | traceroute google.com |
| 28 | nmap | scan ports | nmap -sV 192.168.1.0/24 |
| 29 | scp | คัดลอกไฟล์ผ่าน SSH | scp file.tar.gz user@server:/tmp/ |
| 30 | rsync | sync ไฟล์ | rsync -avz /data/ user@backup:/data/ |
คำสั่ง System & Process (System Management)
| # | Command | หน้าที่ | ตัวอย่าง |
| 31 | top/htop | ดู process แบบ real-time | htop (สวยกว่า top) |
| 32 | ps | แสดง process | ps aux | grep nginx |
| 33 | kill | หยุด process | kill -9 PID |
| 34 | systemctl | จัดการ service | systemctl restart nginx |
| 35 | journalctl | ดู systemd logs | journalctl -u nginx -f |
| 36 | df | ดู disk space | df -h |
| 37 | free | ดู RAM usage | free -h |
| 38 | uptime | ดู load average | uptime |
| 39 | crontab | ตั้ง scheduled task | crontab -e |
| 40 | uname | ดูข้อมูล OS | uname -a |
คำสั่งขั้นสูง (Advanced)
| # | Command | หน้าที่ | ตัวอย่าง |
| 41 | tar | บีบอัด/แตกไฟล์ | tar czf backup.tar.gz /data |
| 42 | chmod | เปลี่ยน permission | chmod 755 script.sh |
| 43 | chown | เปลี่ยนเจ้าของ | chown -R www-data:www-data /var/www |
| 44 | ln | สร้าง symlink | ln -s /opt/app/current /opt/app/latest |
| 45 | xargs | ส่ง output เป็น argument | find . -name "*.tmp" | xargs rm |
| 46 | tee | เขียน output ทั้งหน้าจอ+ไฟล์ | echo "test" | tee log.txt |
| 47 | screen/tmux | terminal multiplexer | tmux new -s deploy |
| 48 | ssh-keygen | สร้าง SSH key | ssh-keygen -t ed25519 |
| 49 | iptables | firewall rules | iptables -L -n |
| 50 | docker | จัดการ containers | docker ps -a |
เทคนิค Command Line ที่ช่วยประหยัดเวลา
- Pipe ( | ) — ส่ง output ของคำสั่งหนึ่งไปเป็น input ของอีกคำสั่งเช่น
cat log | grep error | wc -l
- Redirect ( >, >> ) — เขียน output ลงไฟล์
> ทับ >> ต่อท้าย
- Ctrl+R — ค้นหาคำสั่งที่เคยพิมพ์ประหยัดเวลามาก
- !! และ !$ —
!! รันคำสั่งล่าสุดซ้ำ sudo !! รันคำสั่งล่าสุดด้วย sudo
- alias — สร้างคำสั่งลัดเช่น
alias ll='ls -lah' ใส่ใน .bashrc
- {} — Brace expansion เช่น
mkdir -p project/{src, test, docs}
Q: ควรเรียน Bash หรือ Zsh?
เริ่มจาก Bash ก่อนครับเพราะเป็น default shell ของ server ส่วนใหญ่เมื่อคล่องแล้วค่อยเปลี่ยนเป็น Zsh + Oh My Zsh ที่มี plugin และ theme สวยๆช่วยเพิ่ม productivity