Linux 常用命令 100 个:文件、网络、进程管理
Linux 命令是开发者的基本功。本文整理 100 个常用命令。
文件操作
ls -la # 列出文件
cd /path # 切换目录
pwd # 当前目录
mkdir -p dir # 创建目录
rm -rf dir # 删除目录
cp -r src dst # 复制
mv src dst # 移动/重命名
find . -name "*.java" # 查找文件
grep -r "text" . # 搜索内容
cat file # 查看文件
head -n 10 file # 查看前10行
tail -f file # 实时查看
wc -l file # 统计行数
文件权限
chmod 755 file # 设置权限
chown user:group file # 修改所有者
文本处理
awk '{print $1}' file # 提取第一列
sed 's/old/new/g' file # 替换文本
sort file # 排序
uniq file # 去重
cut -d':' -f1 /etc/passwd # 分割文本
网络命令
ping google.com # 测试连通性
curl -X GET url # HTTP 请求
wget url # 下载文件
netstat -tlnp # 查看端口
ss -tlnp # 查看端口
ifconfig # 网络配置
ip addr # IP 地址
nslookup domain # DNS 查询
traceroute host # 路由追踪
进程管理
ps aux # 查看进程
ps -ef | grep java # 查找进程
top # 实时监控
htop # 增强版 top
kill -9 pid # 强制杀进程
pkill -f "java" # 按名称杀进程
nohup command & # 后台运行
系统信息
uname -a # 系统信息
cat /etc/os-release # 发行版信息
df -h # 磁盘使用
du -sh dir # 目录大小
free -h # 内存使用
uptime # 运行时间
whoami # 当前用户
压缩解压
tar -czf archive.tar.gz dir # 压缩
tar -xzf archive.tar.gz # 解压
zip -r archive.zip dir # zip 压缩
unzip archive.zip # zip 解压
服务管理
systemctl start nginx # 启动服务
systemctl stop nginx # 停止服务
systemctl status nginx # 查看状态
systemctl enable nginx # 开机启动
journalctl -u nginx # 查看日志
总结
掌握这些常用 Linux 命令,可以高效地管理服务器和排查问题。