简体   繁体   中英

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 second 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM