Tham Khảo Lệnh Linux
Tra cứu nhanh các lệnh Linux/Unix thiết yếu: quản lý file, xử lý văn bản, tiến trình, mạng và nhiều hơn nữa.
File & Thư mục
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 usageXử lý Văn bản
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)Tiến trình
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 foregroundPhân quyền & Quyền sở hữu
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 maskMạng
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 efficientlyNén & Giải nén
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 fileThông tin Hệ thống
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 commandGiới thiệu công cụ
Tham Khảo Lệnh Linux cung cấp bộ sưu tập các lệnh Linux/Unix thiết yếu được tổ chức thành bảy danh mục: quản lý file và thư mục, xử lý văn bản, kiểm soát tiến trình, phân quyền và quyền sở hữu, mạng, nén giải nén, và thông tin hệ thống.
Mỗi lệnh có ví dụ sử dụng thực tế và mô tả ngắn gọn. Sử dụng hộp tìm kiếm để lọc nhanh theo tên lệnh hoặc từ khóa mô tả.
Cách sử dụng
- Nhập tên lệnh hoặc từ khóa vào hộp tìm kiếm.
- Cuộn qua các danh mục để duyệt lệnh.
- Xem lệnh và mô tả, sau đó sử dụng trong terminal.
- Thay thế các placeholder trong dấu ngoặc nhọn (<dir>, <file>, v.v.) bằng giá trị thực.
Trường hợp sử dụng
Kỹ sư DevOps viết script triển khai, sysadmin gỡ lỗi máy chủ, lập trình viên kiểm tra quyền file hoặc tiến trình, và người mới học các lệnh cơ bản Linux.
Câu hỏi thường gặp
- Dấu ngoặc nhọn (<>) có nghĩa gì? Dấu ngoặc nhọn là placeholder. Thay <dir> bằng đường dẫn thư mục thực, <file> bằng tên file, <pid> bằng ID tiến trình, v.v.
- Nếu lệnh không tìm thấy thì làm gì? Một số lệnh như htop không được cài sẵn. Hãy cài qua trình quản lý gói (vd: sudo apt install htop) hoặc kiểm tra bằng lệnh man.
- Cần lưu ý gì khi dùng sudo? sudo chạy lệnh với quyền siêu người dùng. Các lệnh phá hủy như rm -rf dùng với sudo có thể gây mất dữ liệu không thể phục hồi. Luôn kiểm tra kỹ trước khi thực thi.