linux常用命令(持续更新)
1. grep
1 grep <find_content> <target_file> 2 3 grep -i <find_content> <target_file> # 不区分大小写 4 grep -w <find_content> <target_file> # 精确匹配 5 grep -e <find_content1> -e <find_content2> <target_file> # 联合查找 6 grep -n <find_content> <target_file> # 显示查找到的内容行号 7 grep -v <find_content> <target_file> # 反向查找(不包含find_content) 8 grep -n <find_content> ./ # 当前路径下递归查找 9 grep -lr <find_content> ./ # 当前路径下递归查找所在文件的文件名 10 grep -E <regex> ./ # 用正则表达式查找
2. find
1 find <target_dir> -name "find_content" 2 3 find <target_dir> -type f # 按类型查找:查找文件 4 find <target_dir> -type d # 按类型查找:查找路径 5 find <target_dir> -type l # 按类型查找:查找符号链接文件 6 7 find <target_dir> -a # 按时间查找:访问时间(access) 8 find <target_dir> -c # 按时间查找:文件权限变更时间(change) 9 find <target_dir> -m # 按时间查找:修改时间(modify) 10 eg: 11 find ./ -mmin -1 # 1分钟内修改过的文件 12 find ./ -mtime -1 # 1天内修改过的文件 13 14 find <target_dir> -user <user_name> # 按用户名查找 15 find <target_dir> -group <group_name> # 按用户组查找
3. sed
1 sed # stream-editor 2 3 sed -e '' <target_file> # 不改变target_file原文件,会显示出缓冲区的内容 4 sed -n '' <target_file> # 不改变target_file原文件,不显示出缓冲区的内容,只显示修改还的内容 5 sed -i '' <target_file> # 修改target_file原文件 6 sed -ie '' <target_file> # 修改target_file原文件, 并将源文件备份为target_filee 7 sed -f <shell_file> <target_file> # 用脚本shell_file配合sed修改target_file 8 选项多次使用:sed -e '' -e '' -e '' <target_file> 9 10 6个脚本参数 11 i insert # 指定行前插入 12 eg: 13 sed -i '1ithe \inserted line' test.md # 文件test.md的第1行前插入"the inserted line" 14 15 a append # 指定行后追加 16 eg: 17 sed -i '1athe \appened line' test.md # 文件test.md的第1行后追加"the appened line" 18 19 d delete # 删除 20 eg: 21 sed -i '1d' test.md # 删除文件test.md的第1行 22 23 c copy # 指定行覆盖 24 eg: 25 sed -i '1coverrider' test.md # 文件test.md的第1行内容替换为"overrider" 26 27 s substitude # 替换指定的内容 28 eg: 29 sed -e '1s/old/new/' test.md # 局部替换:用"new"替换文件test.md第1行中的第一个"old" 30 sed -e '1s/old/new/g' test.md # 全局替换:用"new"替换文件test.md第1行中的所有"old" 31 32 p print # 打印 33 eg: 34 sed -n '1p' test.md # 将test.md第1行中的内容打印出来
4. wc
1 wc # word count 2 3 wc <file.md> 4 2 3 15 file.md # 2: 文件file.md有2 lines 5 # 3: 文件file.md有3 words 6 # 15: 文件file.md有15 Bytes 7 # file.md: 文件名 8 9 wc -l <file.md> # line 10 wc -w <file.md> # word 11 wc -c <file.md> # Bytes 12 wc -m <file.md> # 字符数
5. tar
1 tar -cf <file.tar> <src_file> # 将src_file压缩成file.tar 2 tar -xf <file.tar> # 将file.tar解压 3 4 tar -zcf <file.tar.gz> <src_file> # 用gz算法压缩 5 tar -zxf <file.tar.gz> # 用gz算法解压 6 7 tar -v # 解压detail显示 8 注意: -f参数指定文件的,需要放在其他参数的最后
6. tail & head
1 TODO
Reference
My CSDN主页 https://blog.csdn.net/qq_44818816
感谢Bilibili UP主 Ternurafl https://space.bilibili.com/3494379920558585
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~