[英]grep command to find files
I'm looking for a command that use grep to search in /usr/bin for all the files who have 2 links and sort them in ascending.我正在寻找一个命令,该命令使用 grep 在 /usr/bin 中搜索所有具有 2 个链接的文件并按升序对它们进行排序。
The second command I'm looking for must use the first one and display just the files that contain the "x"我正在寻找的第二个命令必须使用第一个命令并仅显示包含“x”的文件
Thanks you谢谢
You can do this direct from grep, eg:您可以直接从 grep 执行此操作,例如:
grep -r --include=*.py "HOSTS" .
will search recursively ('-r') under the current directory ('.') in all python files ('*.py') for the string "HOSTS".将在所有 python 文件 ('*.py') 中的当前目录 ('.') 下递归 ('-r') 搜索字符串“HOSTS”。
This would do这会做
find /usr/bin -links 2 -print0 | xargs -0 ls -adltr
modify the ls to do the sorting you require修改 ls 以进行您需要的排序
find /usr/bin -links 2 -print0 | xargs -0 grep -l "x"
Files containing the "x" :)包含“x”的文件:)
If you meant: 'contain the x' as 'are executable (x appears in ls -l output), use如果您的意思是:“包含 x”为“可执行”(x 出现在 ls -l 输出中),请使用
find /usr/bin -links 2 -executable -print0 | ls -adltr
To see only dirs:仅查看目录:
find /usr/bin -links 2 -type d -executable -print0 | ls -adltr
To see only files:仅查看文件:
find /usr/bin -links 2 -type f -executable -print0 | ls -adltr
Note: directories get 2 links by default ( .
is a link) so you might want to look for -links 3
with directories注意:默认情况下,目录获得 2 个链接(
.
是一个链接),因此您可能需要查找带有目录的-links 3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.