คู่มือคำสั่ง Linux
อ้างอิงคำสั่ง Linux/Unix ที่จำเป็นอย่างรวดเร็ว: การจัดการไฟล์ การประมวลผลข้อความ กระบวนการ เครือข่าย และอื่นๆ
ไฟล์ & ไดเรกทอรี
ls -laList files with details and hidden filescd <dir>Change directorypwdPrint working directorymkdir -p <dir>Create directory (and parents)rm -rf <dir>Remove directory recursively (careful!)cp -r <src> <dest>Copy files/directories recursivelymv <src> <dest>Move or rename file/directorytouch <file>Create empty file or update timestampfind . -name "*.txt"Find files by name patternfind . -type f -size +10MFind files larger than 10MBdu -sh *Show disk usage of each itemdf -hShow disk space usageการประมวลผลข้อความ
cat <file>Print file contentsless <file>Page through file (q to quit)head -n 20 <file>Show first 20 linestail -n 20 <file>Show last 20 linestail -f <file>Follow file (live log viewing)grep -r "pattern" .Search for pattern recursivelygrep -i "pattern" <file>Case-insensitive searchgrep -n "pattern" <file>Show line numbers in resultssed -i "s/old/new/g" <file>Replace text in file in-placeawk '{print $1}' <file>Print first columnsort <file>Sort lines alphabeticallysort -n -k2 <file>Sort numerically by 2nd columnuniq -cCount and deduplicate adjacent lineswc -l <file>Count lines in filecut -d"," -f1,3 <file>Cut specific columns (CSV)กระบวนการ
ps auxList all running processestopInteractive process viewerhtopEnhanced process viewer (if installed)kill <pid>Terminate process by PIDkill -9 <pid>Force kill processpkill <name>Kill processes by namepgrep <name>Find PIDs by process namenohup <cmd> &Run command immune to hangups, in backgroundjobsList background jobsbg %1Resume job 1 in backgroundfg %1Bring job 1 to foregroundสิทธิ์ & ความเป็นเจ้าของ
chmod 755 <file>Set rwxr-xr-x permissionschmod +x <file>Make file executablechown user:group <file>Change file owner and groupsudo <cmd>Run command as superusersudo -iSwitch to root shellsu - <user>Switch to another userumask 022Set default permission maskเครือข่าย
curl -I <url>Show response headers onlycurl -L -o file <url>Download file following redirectswget <url>Download fileping <host>Test network connectivitytraceroute <host>Trace network path to hostnslookup <domain>DNS lookupdig <domain>Detailed DNS lookupnetstat -tulnShow listening portsss -tulnShow listening ports (modern)ssh user@hostConnect via SSHscp <file> user@host:/pathCopy file via SSHrsync -avz src/ user@host:dest/Sync files efficientlyการเก็บถาวร & การบีบอัด
tar -czf archive.tar.gz <dir>Create gzip compressed archivetar -xzf archive.tar.gzExtract gzip archivetar -cjf archive.tar.bz2 <dir>Create bzip2 compressed archivezip -r archive.zip <dir>Create zip archiveunzip archive.zipExtract zip archivegzip <file>Compress file with gzipgunzip <file>.gzDecompress gzip fileข้อมูลระบบ
uname -aSystem and kernel informationcat /etc/os-releaseOS version informationfree -hMemory usageuptimeSystem uptime and loadwhoWho is logged inidCurrent user and group IDsenvShow environment variablesexport VAR=valueSet environment variablewhich <cmd>Find command pathhistoryCommand historyman <cmd>Manual page for a commandเกี่ยวกับเครื่องมือนี้
คู่มือคำสั่ง Linux ให้บริการคอลเลกชันคำสั่ง Linux/Unix ที่จำเป็น จัดระเบียบเป็นเจ็ดหมวดหมู่ ได้แก่ การจัดการไฟล์และไดเรกทอรี การประมวลผลข้อความ การควบคุมกระบวนการ สิทธิ์และความเป็นเจ้าของ เครือข่าย การเก็บถาวรและการบีบอัด และข้อมูลระบบ
แต่ละคำสั่งมีตัวอย่างการใช้งานจริงและคำอธิบายสั้นๆ ใช้ช่องค้นหาเพื่อกรองตามชื่อคำสั่งหรือคีย์เวิร์ดของคำอธิบาย
วิธีใช้งาน
- พิมพ์ชื่อคำสั่งหรือคีย์เวิร์ดในช่องค้นหา
- เลื่อนดูหมวดหมู่เพื่อค้นหาคำสั่ง
- ตรวจสอบคำสั่งและคำอธิบาย แล้วใช้งานใน terminal
- แทนที่ 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 อาจทำให้ข้อมูลสูญหายอย่างถาวร ควรตรวจสอบอย่างละเอียดก่อนรัน