美文网首页
Linux中常用查找命令.md

Linux中常用查找命令.md

作者: 回忆的时间沙漏 | 来源:发表于2019-05-21 16:25 被阅读0次

目前用的两个比较方便的查找命令

  • find
  • grep

find

选项

  • 列出当前目录及子目录下所有文件和文件夹
find .
  • 在/home目录下查找以.txt结尾的文件名
find /home -name "*.txt"
  • 在/home目录下查找以.txt结尾的文件名,但是忽略大小写
find /home -iname "*.txt"
  • 当前目录及子目录下查找所有以.txt和.pdf结尾的文件
find . \( -name "*.txt" -o -name "*.pdf" \)

或

find . -name "*.txt" -o -name "*.pdf" 
  • 找出/home下不是以.txt结尾的文件
find /home ! -name "*.txt"
  • 匹配文件路径或者文件
find /usr/ -path "*local*"

grep

选项

  • c:只输出匹配行的计数
#ps -ef | grep  -c python
5
  • i:不区分大小写
  • h:查询多文件时不显示文件名
  • l:查询多文件时只输出包含匹配字符的文件名
  • n:显示匹配行及行号
#ps -ef | grep -n python
289:root       3266      1  0 May20 ?        00:00:51 /usr/bin/python -Es /usr/sbin/tuned -l -P
295:root       3470      1  0 May20 ?        00:01:05 /usr/bin/python /usr/bin/supervisord -c /etc/supervisord.conf
624:root      49455  49423  0 16:13 ?        00:00:00 python main.py mxvote show
626:root      49560 100819  0 16:13 pts/2    00:00:00 grep --color=auto -n python
721:root     108367 107290  7 15:02 pts/6    00:05:16 /usr/bin/python /bin/dstat -l -m -r -c --top-io --top-mem --top-cpu
  • s:不显示不存在或无匹配文本的错误信息
  • v:显示不包含匹配文本的所有行

规则表达式

  • ^ : 行起始标志
cat test.txt | grep -E "^ben"     # 匹配test.txt中以ben开始的行
  • $ : 行结尾标志
cat test.txt | grep -E "ben$"   匹配test.txt中以ben结尾的行
  • [^] :匹配除[^字符]之外的任何一个字符
  - cat test.txt | grep -E "9[^0]"   匹配test.txt中不是90的信息,但是会匹配91,92
  - cat test.txt | grep -E "grep '^[^#]'  files   匹配test.txt中行首不为#的行作为输出
    • : 匹配零个或多个先前字符
  - '*grep'匹配所有一个或多个空格后紧跟grep的行

相关文章

  • Linux中常用查找命令.md

    目前用的两个比较方便的查找命令 find grep find 选项 列出当前目录及子目录下所有文件和文件夹 在/h...

  • linux常用命令

    linux常用命令 文件查找 find [指定目录][指定条件][指定动作] 指定目录:​ find命令所查找的目...

  • Linux中通过grep命令检索文件内容

    Linux系统中搜索、查找文件中的内容,一般最常用的是grep命令,另外还有egrep命令,同时vi命令也支持文件...

  • Linux命令总结(+使用例子)

    概要:Linux中的命令很多,在这里做个小记,便于自己查找。在常用的命令下用 * 再次加以标记。 1、ls命令 一...

  • Linux中的文件查找技巧

    前言 Linux常用命令中,有些命令可以帮助我们查找二进制文件,帮助手册或源文件的位置,也有的命令可以帮助我们查找...

  • Linux命令之文件管理 (四十九)

    Linux whereis命令Linux whereis命令用于查找文件。 该指令会在特定目录中查找符合条件的文件...

  • Mac 常用操作

    一、常用命令 Linux的五个查找命令:find,locate,whereis,which,type 1、find...

  • Module-Git使用手册

    Linux-Git使用手册.md GitHub插入MarkDown图片 Github常用脚本 使用脚本 命令大全 ...

  • Linux的查找命令—find whereis which

    学习Linux里常用的查找命令:find whereis which whereis命令只能用于程序名的搜索;...

  • Linux&mac常用命令

    记录常用的linux命令,方便后期使用时查找,每种命令只记录常用方式 压缩 解压缩 ssh远程登录 scp本机和服...

网友评论

      本文标题:Linux中常用查找命令.md

      本文链接:https://www.haomeiwen.com/subject/bcejzqtx.html