作家
登录

如何在Linux shell中找出所有包含指定文本的文件

作者: 来源: 2017-12-18 10:45:05 阅读 我要评论

开辟者大年夜赛路演 | 12月16日,技巧立异,北京不见不散


难度:轻易

商定:

  • # - 须要应用 root 权限来履行指天敕令,可以直接应用 root 用户来履行也可以应用 sudo 敕令
  • $ - 可以应用通俗用户来履行指天敕令

案例

非递归搜刮包含指定字符串的文件

膳绫擎案例中忽视了所有的子目次。所谓递归搜刮就是指同时搜刮所有的子目次。

第一个例子让我们来搜刮 /etc/ 目次下所有包含 stretch 字符串的文件,但不去搜刮个中的子目次:

  1. # grep -s stretch /etc/*
  2. /etc/os-release:PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
  3. /etc/os-release:VERSION="9 (stretch)"

grep-s 选项会在发明不存在或者不克不及攫取的文件时隐蔽报错信息。结不雅显示除了文件名之外,还有包含请求字符串的行也被一发誓出了。

递归地搜刮包含指定字符串的文件

下面的敕令会在 /etc/ 及其子目次中搜刮包含 stretch 字符串的文件:

  1. # grep -R stretch /etc/*
  2. /etc/apt/sources.list:# deb cdrom:[Debian GNU/Linux testing _Stretch_ - Official Snapshot amd64 NETINST Binary-1 20170109-05:56]/ stretch main
  3. /etc/apt/sources.list:#deb cdrom:[Debian GNU/Linux testing _Stretch_ - Official Snapshot amd64 NETINST Binary-1 20170109-05:56]/ stretch main
  4. /etc/apt/sources.list:deb http://ftp.au.debian.org/debian/ stretch main
  5. /etc/apt/sources.list:deb-src http://ftp.au.debian.org/debian/ stretch main
  6. /etc/apt/sources.list:deb http://security.debian.org/debian-security stretch/updates main
  7. /etc/apt/sources.list:deb-src http://security.debian.org/debian-security stretch/updates main
  8. /etc/dictionaries-common/words:backstretch
  9. /etc/dictionaries-common/words:backstretch's
  10. /etc/dictionaries-common/words:backstretches
  11. /etc/dictionaries-common/words:homestretch
  12. /etc/dictionaries-common/words:homestretch's
  13. /etc/dictionaries-common/words:homestretches
  14. /etc/dictionaries-common/words:outstretch
  15. /etc/dictionaries-common/words:outstretched
  16. /etc/dictionaries-common/words:outstretches
  17. /etc/dictionaries-common/words:outstretching
  18. /etc/dictionaries-common/words:stretch
  19. /etc/dictionaries-common/words:stretch's
  20. /etc/dictionaries-common/words:stretched
  21. /etc/dictionaries-common/words:stretcher
  22. /etc/dictionaries-common/words:stretcher's
  23. /etc/dictionaries-common/words:stretchers
  24. /etc/dictionaries-common/words:stretches
  25. /etc/dictionaries-common/words:stretchier
  26. /etc/dictionaries-common/words:stretchiest
  27. /etc/dictionaries-common/words:stretching
     1/4    1 2 3 4 下一页 尾页

      推荐阅读

      腾讯发现者揭秘:怎么应对TensorFlow的安全风险,修复有多难

    开辟者大年夜赛路演 | 12月16日,技巧立异,北京不见不散 12 月 15 日,雷锋网报道,腾讯安然平台部预研团队发明谷歌人工智能进修体系 TensorFlow 存在自身安然风险,可被黑客应用带来安然>>>详细阅读


    本文标题:如何在Linux shell中找出所有包含指定文本的文件

    地址:http://www.17bianji.com/lsqh/39864.html

关键词: 探索发现

乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

网友点评
自媒体专栏

评论

热度

精彩导读
栏目ID=71的表不存在(操作类型=0)