TL
Tool Lab
💰Donate
💰Donate

คู่มือคำสั่ง Linux

อ้างอิงคำสั่ง Linux/Unix ที่จำเป็นอย่างรวดเร็ว: การจัดการไฟล์ การประมวลผลข้อความ กระบวนการ เครือข่าย และอื่นๆ

ไฟล์ & ไดเรกทอรี

ls -laList files with details and hidden files
cd <dir>Change directory
pwdPrint working directory
mkdir -p <dir>Create directory (and parents)
rm -rf <dir>Remove directory recursively (careful!)
cp -r <src> <dest>Copy files/directories recursively
mv <src> <dest>Move or rename file/directory
touch <file>Create empty file or update timestamp
find . -name "*.txt"Find files by name pattern
find . -type f -size +10MFind files larger than 10MB
du -sh *Show disk usage of each item
df -hShow disk space usage

การประมวลผลข้อความ

cat <file>Print file contents
less <file>Page through file (q to quit)
head -n 20 <file>Show first 20 lines
tail -n 20 <file>Show last 20 lines
tail -f <file>Follow file (live log viewing)
grep -r "pattern" .Search for pattern recursively
grep -i "pattern" <file>Case-insensitive search
grep -n "pattern" <file>Show line numbers in results
sed -i "s/old/new/g" <file>Replace text in file in-place
awk '{print $1}' <file>Print first column
sort <file>Sort lines alphabetically
sort -n -k2 <file>Sort numerically by 2nd column
uniq -cCount and deduplicate adjacent lines
wc -l <file>Count lines in file
cut -d"," -f1,3 <file>Cut specific columns (CSV)

กระบวนการ

ps auxList all running processes
topInteractive process viewer
htopEnhanced process viewer (if installed)
kill <pid>Terminate process by PID
kill -9 <pid>Force kill process
pkill <name>Kill processes by name
pgrep <name>Find PIDs by process name
nohup <cmd> &Run command immune to hangups, in background
jobsList background jobs
bg %1Resume job 1 in background
fg %1Bring job 1 to foreground

สิทธิ์ & ความเป็นเจ้าของ

chmod 755 <file>Set rwxr-xr-x permissions
chmod +x <file>Make file executable
chown user:group <file>Change file owner and group
sudo <cmd>Run command as superuser
sudo -iSwitch to root shell
su - <user>Switch to another user
umask 022Set default permission mask

เครือข่าย

curl -I <url>Show response headers only
curl -L -o file <url>Download file following redirects
wget <url>Download file
ping <host>Test network connectivity
traceroute <host>Trace network path to host
nslookup <domain>DNS lookup
dig <domain>Detailed DNS lookup
netstat -tulnShow listening ports
ss -tulnShow listening ports (modern)
ssh user@hostConnect via SSH
scp <file> user@host:/pathCopy file via SSH
rsync -avz src/ user@host:dest/Sync files efficiently

การเก็บถาวร & การบีบอัด

tar -czf archive.tar.gz <dir>Create gzip compressed archive
tar -xzf archive.tar.gzExtract gzip archive
tar -cjf archive.tar.bz2 <dir>Create bzip2 compressed archive
zip -r archive.zip <dir>Create zip archive
unzip archive.zipExtract zip archive
gzip <file>Compress file with gzip
gunzip <file>.gzDecompress gzip file

ข้อมูลระบบ

uname -aSystem and kernel information
cat /etc/os-releaseOS version information
free -hMemory usage
uptimeSystem uptime and load
whoWho is logged in
idCurrent user and group IDs
envShow environment variables
export VAR=valueSet environment variable
which <cmd>Find command path
historyCommand history
man <cmd>Manual page for a command

เกี่ยวกับเครื่องมือนี้

คู่มือคำสั่ง Linux ให้บริการคอลเลกชันคำสั่ง Linux/Unix ที่จำเป็น จัดระเบียบเป็นเจ็ดหมวดหมู่ ได้แก่ การจัดการไฟล์และไดเรกทอรี การประมวลผลข้อความ การควบคุมกระบวนการ สิทธิ์และความเป็นเจ้าของ เครือข่าย การเก็บถาวรและการบีบอัด และข้อมูลระบบ

แต่ละคำสั่งมีตัวอย่างการใช้งานจริงและคำอธิบายสั้นๆ ใช้ช่องค้นหาเพื่อกรองตามชื่อคำสั่งหรือคีย์เวิร์ดของคำอธิบาย

วิธีใช้งาน

  1. พิมพ์ชื่อคำสั่งหรือคีย์เวิร์ดในช่องค้นหา
  2. เลื่อนดูหมวดหมู่เพื่อค้นหาคำสั่ง
  3. ตรวจสอบคำสั่งและคำอธิบาย แล้วใช้งานใน terminal
  4. แทนที่ placeholder ในวงเล็บมุม (<dir>, <file> เป็นต้น) ด้วยค่าจริง

กรณีการใช้งาน

วิศวกร DevOps ที่เขียนสคริปต์การ deploy, sysadmin ที่แก้ไขปัญหาเซิร์ฟเวอร์, นักพัฒนาที่ตรวจสอบสิทธิ์ไฟล์หรือกระบวนการ และผู้เริ่มต้นเรียนรู้พื้นฐาน command-line ของ Linux

คำถามที่พบบ่อย

  • วงเล็บมุม (<>) หมายความว่าอะไร? วงเล็บมุมคือ placeholder แทนที่ <dir> ด้วยเส้นทางไดเรกทอรีจริง <file> ด้วยชื่อไฟล์ <pid> ด้วย process ID เป็นต้น
  • ถ้าไม่พบคำสั่งต้องทำอย่างไร? บางคำสั่งเช่น htop ไม่ได้ติดตั้งมาโดยค่าเริ่มต้น ติดตั้งผ่าน package manager (เช่น sudo apt install htop) หรือตรวจสอบด้วยคำสั่ง man
  • ควรระวังอะไรเมื่อใช้ sudo? sudo รันคำสั่งด้วยสิทธิ์ superuser คำสั่งที่ทำลายข้อมูลเช่น rm -rf เมื่อใช้กับ sudo อาจทำให้ข้อมูลสูญหายอย่างถาวร ควรตรวจสอบอย่างละเอียดก่อนรัน