SiamCafe · Blog
Linux Command Line 50
บทความ

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หน้าที่ตัวอย่าง
1lsแสดงรายการไฟล์ls -lah แสดงทั้งหมดพร้อมขนาด
2cdเปลี่ยน directorycd /var/log
3pwdแสดง directory ปัจจุบันpwd → /home/user
4mkdirสร้าง directorymkdir -p app/{src, config, logs}
5rmลบไฟล์/directoryrm -rf old_backup/ (ระวัง!)
6cpคัดลอกไฟล์cp -r src/ dest/
7mvย้าย/เปลี่ยนชื่อmv old.txt new.txt
8findค้นหาไฟล์find / -name "*.log" -mtime +30
9treeแสดง directory treetree -L 2 /etc
10duดูขนาด directorydu -sh /var/log/*

คำสั่งดูและแก้ไขไฟล์ (File Viewing & Editing)

#Commandหน้าที่ตัวอย่าง
11catแสดงเนื้อหาไฟล์cat /etc/hostname
12lessอ่านไฟล์แบบ scrollless /var/log/syslog
13headดู 10 บรรทัดแรกhead -20 access.log
14tailดู 10 บรรทัดท้ายtail -f /var/log/nginx/error.log
15grepค้นหาข้อความgrep -r "error" /var/log/ --include="*.log"
16awkประมวลผลข้อความawk '{print $1}' access.log | sort | uniq -c | sort -rn
17sedแก้ไขข้อความsed -i 's/old/new/g' config.txt
18nanotext editor ง่ายๆnano /etc/nginx/nginx.conf
19vimtext editor ขั้นสูงvim /etc/ssh/sshd_config
20wcนับบรรทัด/คำwc -l access.log

คำสั่ง Network (Networking)

#Commandหน้าที่ตัวอย่าง
21ip addrดู IP addressip addr show eth0
22pingทดสอบเชื่อมต่อping -c 4 google.com
23curlHTTP requestcurl -I https://example.com
24wgetดาวน์โหลดไฟล์wget https://example.com/file.tar.gz
25ssดู open portsss -tulnp (แทน netstat)
26digตรวจ DNSdig +short A example.com
27tracerouteดูเส้นทาง networktraceroute google.com
28nmapscan portsnmap -sV 192.168.1.0/24
29scpคัดลอกไฟล์ผ่าน SSHscp file.tar.gz user@server:/tmp/
30rsyncsync ไฟล์rsync -avz /data/ user@backup:/data/

คำสั่ง System & Process (System Management)

#Commandหน้าที่ตัวอย่าง
31top/htopดู process แบบ real-timehtop (สวยกว่า top)
32psแสดง processps aux | grep nginx
33killหยุด processkill -9 PID
34systemctlจัดการ servicesystemctl restart nginx
35journalctlดู systemd logsjournalctl -u nginx -f
36dfดู disk spacedf -h
37freeดู RAM usagefree -h
38uptimeดู load averageuptime
39crontabตั้ง scheduled taskcrontab -e
40unameดูข้อมูล OSuname -a

คำสั่งขั้นสูง (Advanced)

#Commandหน้าที่ตัวอย่าง
41tarบีบอัด/แตกไฟล์tar czf backup.tar.gz /data
42chmodเปลี่ยน permissionchmod 755 script.sh
43chownเปลี่ยนเจ้าของchown -R www-data:www-data /var/www
44lnสร้าง symlinkln -s /opt/app/current /opt/app/latest
45xargsส่ง output เป็น argumentfind . -name "*.tmp" | xargs rm
46teeเขียน output ทั้งหน้าจอ+ไฟล์echo "test" | tee log.txt
47screen/tmuxterminal multiplexertmux new -s deploy
48ssh-keygenสร้าง SSH keyssh-keygen -t ed25519
49iptablesfirewall rulesiptables -L -n
50dockerจัดการ containersdocker 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