/etc/os-release
搜刮时包含/清除指定文件
grep
敕令也可以只在指定文件中进行搜刮。比如,我们可以只在设备文件(扩大名为.conf
)中搜刮指定的文本/字符串。 下面这个例子就会在 /etc
目次中搜刮带字符串 bash
且所有扩大名为 .conf
的文件:
# grep -Ril bash /etc/*.conf
OR
# grep -Ril --include=\*.conf bash /etc/*
/etc/adduser.conf
默认情况下搜刮是大年夜小写敏感的,也就是说当搜刮字符串 stretch
时只会包含大年夜小写一致内容的文件。
类似的,也可以应用 --exclude
来清除特定的文件:
# grep -Ril --exclude=\*.conf bash /etc/*
/etc/alternatives/view
/etc/alternatives/vim
/etc/alternatives/vi
/etc/alternatives/vimdiff
/etc/alternatives/rvim
/etc/alternatives/ex
/etc/alternatives/rview
/etc/bash.bashrc
/etc/bash_completion.d/grub
/etc/cron.daily/apt-compat
/etc/cron.daily/exim4-base
/etc/dictionaries-common/default.hash
/etc/dictionaries-common/words
/etc/inputrc
/etc/passwd
/etc/passwd-
/etc/profile
/etc/shells
/etc/skel/.profile
/etc/skel/.bashrc
/etc/skel/.bash_logout
搜刮时清除指定目次
跟文件一样,grep
也能在搜刮时清除指定目次。 应用 --exclude-dir
选项久煨。
下面这个例子会搜刮 /etc
目次中搜有包含字符串 stretch
的文件,但不包含 /etc/grub.d
目次下的文件:
# grep --exclude-dir=/etc/grub.d -Rwl stretch /etc/*
/etc/apt/sources.list
/etc/dictionaries-common/words
/etc/os-release
显示包含搜刮字符串的行号
-n
选项还会显示指定字符串地点行的行号:
推荐阅读
腾讯发现者揭秘:怎么应对TensorFlow的安全风险,修复有多难
开辟者大年夜赛路演 | 12月16日,技巧立异,北京不见不散 12 月 15 日,雷锋网报道,腾讯安然平台部预研团队发明谷歌人工智能进修体系 TensorFlow 存在自身安然风险,可被黑客应用带来安然>>>详细阅读
本文标题:如何在Linux shell中找出所有包含指定文本的文件
地址:http://www.17bianji.com/lsqh/39864.html
1/2 1