开发者

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.

The s开发者_StackOverflow社区econd command I'm looking for must use the first one and display just the files that contain the "x"

Thanks you


You can do this direct from grep, eg:

grep -r --include=*.py "HOSTS" .

will search recursively ('-r') under the current directory ('.') in all python files ('*.py') for the string "HOSTS".


This would do

find /usr/bin -links 2 -print0 | xargs -0 ls -adltr

modify the ls to do the sorting you require

find /usr/bin -links 2 -print0 | xargs -0 grep -l "x"

Files containing the "x" :)


If you meant: 'contain the x' as 'are executable (x appears in ls -l output), use

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜