Linux-使用 grep 查找文件
我是 Linux 新手,我真的不知道我做错了什么。 我需要在目录 /usr/sbin 中查找名称中包含“fs”且不以“x”开头的文件。 我需要将结果写入 111.txt 文件,但无法使用 find 来执行此操作。 我尝试了这个命令,但它不起作用。
grep -r -v '^x' -w 'fs' /usr/sbin/ > 111.txt
I'm new to Linux and I don't really know what I'm doing wrong.
I need to find files in catalog /usr/sbin that have 'fs' in their name and don't start with 'x'.
I need to write results in 111.txt file but cannot use find to do this.
I tried this command but it doesn't work.
grep -r -v '^x' -w 'fs' /usr/sbin/ > 111.txt
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将 find 通过管道传输到两个链接的 grep 命令中:
You could pipe find into two chained grep commands instead:
grep
不是为此目的,您应该使用find
代替:grep
isn't meant for that, you should usefind
instead:尝试
shopt -s extglob
启用“扩展通配”,它支持@(pattern1|pattern2)
等模式。请参阅 extglob 部分 (glob - Greg 的维基。这个答案最初是建议的
这已被破坏,因为它排除了名称以
fs
开头的文件。Try
shopt -s extglob
enables "extended globbing", which supports patterns like@(pattern1|pattern2)
. See the extglob section in glob - Greg's Wiki.This answer originally suggested
That was broken because it excludes files whose names begin with
fs
.