linux常用指令
John DoeLinux常用命令速查手册
nohup python train_new.py > train.log 2>&1 & 离线也可运行指令
📊 磁盘空间管理
查看磁盘使用情况
1 2 3 4
| df -h df -h /home du -sh /path/to/dir du -h --max-depth=1
|
查找大文件
1 2
| du -ah /path | sort -rh | head -n 20 find / -type f -size +100M
|
📁 文件和目录操作
查看文件列表
1 2 3 4 5 6
| ls -l ls -lh ls -lht ls -lhS ls -la ls -l | head -n 10
|
文件搜索
1 2 3 4
| find /path -name "*.log" find /path -type f -mtime -7 find /path -type f -mtime +30 grep -r "关键词" /path
|
创建和复制
1 2 3 4
| mkdir -p /path/to/new/dir cp -r source/ destination/ cp -p file1 file2 rsync -av source/ destination/
|
🗑️ 删除操作
基本删除命令
1 2 3 4
| rm file.txt rm -r /path/to/dir rm -rf /path/to/dir rm /path/to/dir/*
|
安全删除(推荐)
1 2 3
| rm -i file.txt rm -ri /path/to/dir ls -la /path/to/dir
|
清空日志文件(不删除文件本身)
1 2
| > /var/log/app.log truncate -s 0 /var/log/app.log
|
⚠️ 删除操作注意事项
- 永久删除: Linux的
rm命令是永久删除,没有回收站
- 谨慎使用:
rm -rf / 会删除整个系统,永远不要执行
- 避免通配符错误:
rm -rf /path /to/dir (空格错位)会很危险
- 先预览: 用
ls或find先查看要删除的内容
- 重要数据: 删除前务必备份
📝 文件内容查看
1 2 3 4 5 6
| cat file.txt head -n 20 file.txt tail -n 20 file.txt tail -f /var/log/app.log less file.txt grep "ERROR" app.log
|
🔐 权限管理
1 2 3 4
| chmod 755 file.sh chmod +x script.sh chown user:group file.txt chown -R user:group /path/to/dir
|
💾 压缩和解压
1 2 3 4 5 6 7 8
| tar -czf archive.tar.gz /path/to/dir tar -xzf archive.tar.gz tar -xzf archive.tar.gz -C /target/
zip -r archive.zip /path/to/dir unzip archive.zip
|
🔍 系统监控
1 2 3 4 5 6
| top htop ps aux ps aux | grep nginx free -h uptime
|
🌐 网络相关
1 2 3 4 5
| netstat -tulnp ss -tulnp ping -c 4 google.com curl -I https://example.com wget https://example.com/file
|
💡 实用技巧
命令历史
快捷操作
1 2 3 4 5
| cd - !! sudo !! Ctrl + C Ctrl + Z
|
管道和重定向
1 2 3 4
| command > file.txt command >> file.txt command 2>&1 | tee log.txt command1 | command2
|
⚠️ 重要安全提示
- root权限: 谨慎使用
sudo,确认命令无误再执行
- 备份习惯: 删除或修改重要文件前先备份
- 路径确认: 使用绝对路径避免误操作
- 权限最小化: 不要随意给予777权限
- 定期清理: 清理临时文件和日志,释放磁盘空间
📚 学习资源
man command - 查看命令的详细手册
command --help - 查看命令的帮助信息
tldr command - 查看命令的简明示例(需安装tldr)
最后更新: 2025-11-10