TL
Tool Lab
💰捐赠
💰捐赠

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. 查看命令和说明,然后在终端中使用。
  4. 将尖括号(<>)中的占位符替换为实际值。

使用场景

适合编写部署脚本的 DevOps 工程师、调试服务器问题的系统管理员、检查文件权限或进程的开发人员,以及学习 Linux 命令行基础的初学者。

常见问题

  • 尖括号(<>)代表什么? 尖括号是占位符。请将 <dir> 替换为实际目录路径,<file> 替换为文件名,<pid> 替换为进程 ID,以此类推。
  • 命令未找到怎么办? 某些命令(如 htop)默认未安装。请使用包管理器安装(如 sudo apt install htop),或用 man 命令验证是否可用。
  • 使用 sudo 时需要注意什么? sudo 以超级用户权限运行命令。与 rm -rf 等破坏性命令结合使用可能造成不可逆的数据丢失。执行前务必仔细检查。