目录
- 文件归档与压缩命令
- 查找与定位文件命令
- 权限管理命令
- 网络与远程操作命令
- 系统资源监控命令
- 进程管理命令补充
- 常用文本处理命令
- 实战示例与技巧分享
- 总结与学习建议
- 参考资料
1. 文件归档与压缩命令
Linux终端文件归档与压缩是日常管理的重要部分:
tar
- 打包:
tar -cvf archive.tar /path/to/dir
- 解包:
tar -xvf archive.tar
- 打包并压缩(gzip):
tar -czvf archive.tar.gz /path/to/dir
- 解压.gz:
tar -xzvf archive.tar.gz
- 打包并压缩(bzip2):
tar -cjvf archive.tar.bz2 /path/to/dir
- 解压.bz2:
tar -xjvf archive.tar.bz2
- 打包:
zip
与unzip
- 压缩:
zip -r archive.zip /path/to/dir
- 解压:
unzip archive.zip
- 压缩:
gzip
与gunzip
- 压缩:
gzip file
(生成file.gz) - 解压:
gunzip file.gz
- 压缩:
2. 查找与定位文件命令
find
- 按名字查找:
find /path -name "filename"
- 按时间查找:
find /path -mtime -7
(7天内修改) - 按大小查找:
find /path -size +100M
- 按名字查找:
locate
- 快速定位:
locate filename
(基于数据库,需提前更新updatedb
)
- 快速定位:
which
- 查找命令路径:
which ls
- 查找命令路径:
whereis
- 查找命令及源代码:
whereis python
- 查找命令及源代码:
3. 权限管理命令
chmod
— 修改权限- 数字法:
chmod 755 file
- 字符法:
chmod u+x file
- 数字法:
chown
— 修改所有者chown user:group file
umask
— 设置默认权限掩码- 查看权限:
ls -l
4. 网络与远程操作命令
ping
— 测试网络连通性curl
— 命令行HTTP请求工具wget
— 下载文件工具ssh
— 远程登录scp
— 远程复制文件netstat
/ss
— 网络连接状态查看ifconfig
/ip addr
— 网络接口信息
5. 系统资源监控命令
free
— 查看内存使用情况df
— 查看磁盘使用情况du
— 目录大小统计top
/htop
— 动态监控进程资源vmstat
— 系统性能统计
6. 进程管理命令补充
ps aux
— 查看所有进程kill
— 发送信号终止进程killall
— 根据进程名杀死进程jobs
、fg
、bg
— 管理后台任务nohup
— 让程序后台运行且不受挂断影响
7. 常用文本处理命令
cat
— 查看文件内容less
/more
— 分页查看head
/tail
— 查看文件开头/结尾grep
— 搜索匹配内容awk
— 复杂文本处理sed
— 流编辑器,文本替换
8. 实战示例与技巧分享
- 压缩备份项目目录
tar -czvf project_backup_$(date +%F).tar.gz /path/to/project
- 查找大文件释放空间
find / -type f -size +500M -exec ls -lh {} \;
- 远程上传下载
scp user@remote:/path/to/file ./localdir/
- 后台运行程序并保存日志
nohup ./run.sh > output.log 2>&1 &
- 查看实时日志
tail -f /var/log/syslog
9. 总结与学习建议
Linux终端命令众多,但实用命令几百个已足够应对大部分工作。掌握分类思维,结合手册页(man 命令名
)灵活运用,能极大提高工作效率。
建议在实际项目中多练习,熟悉各种命令参数,利用脚本实现自动化,才能做到“Linux终端生存”无压力。
10. 参考资料
- 《鸟哥的Linux私房菜》
- 《Linux命令行大全》
- 官方man手册:
man tar
、man find
、man chmod
等 - 在线资源:https://linux.die.net/
- Linux命令速查
发表回复