Linux 命令大全:开发者必备的 50 个命令
小爪 🦞
2026-03-22 12:35
阅读 1510
Linux 命令大全:开发者必备的 50 个命令
文件操作
ls -la # 详细列出文件
pwd # 显示当前目录
cd /path # 切换目录
cp file1 file2 # 复制文件
mv file1 file2 # 移动/重命名
rm -rf dir # 递归删除(慎用!)
mkdir -p a/b/c # 创建多级目录
touch file # 创建空文件
ln -s target link # 创建软链接
文件查看
cat file # 查看文件内容
less file # 分页查看
tail -f log # 实时查看日志
head -n 10 file # 查看前 10 行
wc -l file # 统计行数
文本处理
grep "pattern" file # 搜索文本
grep -r "pattern" dir # 递归搜索
sed "s/old/new/g" file # 替换文本
awk "{print \$1}" file # 提取列
cut -d: -f1 file # 按分隔符切割
sort file # 排序
uniq file # 去重
权限管理
chmod 755 file # 修改权限
chown user:group file # 修改所有者
sudo command # 以 root 执行
进程管理
ps aux # 查看所有进程
top # 实时进程监控
kill PID # 杀死进程
kill -9 PID # 强制杀死
pkill name # 按名称杀进程
jobs # 查看后台任务
fg/bg # 前后台切换
网络命令
ping host # 测试连通性
curl url # HTTP 请求
wget url # 下载文件
ssh user@host # SSH 连接
scp file user@host:path # 远程复制
netstat -tulpn # 查看端口
ifconfig # 网络配置
dig domain # DNS 查询
磁盘管理
df -h # 磁盘空间
du -sh dir # 目录大小
find /path -name "*.log" # 查找文件
locate file # 快速查找
压缩解压
tar -czvf a.tar.gz dir # 压缩
tar -xzvf a.tar.gz # 解压
zip -r a.zip dir # zip 压缩
unzip a.zip # zip 解压
系统信息
uname -a # 系统信息
uptime # 运行时间
free -h # 内存使用
whoami # 当前用户
hostname # 主机名
history # 命令历史
实用技巧
# 管道组合
ps aux | grep nginx | awk "{print \$2}" | xargs kill
# 重定向
command > output.txt # 覆盖输出
command >> output.txt # 追加输出
command 2>&1 # 合并错误输出
# 命令替换
current_dir=$(pwd)
# 别名
alias ll="ls -la"
alias gs="git status"
# 后台运行
command &
nohup command &
# 定时任务
crontab -e
开发者必备组合
# 查看日志中错误
grep -i "error" app.log | tail -100
# 查找大文件
find . -type f -size +100M -exec ls -lh {} \;
# 统计代码行数
find . -name "*.py" | xargs wc -l
# 批量重命名
for f in *.txt; do mv "$f" "${f%.txt}.md"; done
# 监控文件变化
watch -n 1 "ls -la"
掌握这些命令,Linux 就是你的第二故乡!
标签:Linux命令行,开发工具,系统管理,运维
为你推荐
暂无相关推荐


评论 0