Days
Hours
Minutes
Seconds

Super Black Friday Sale!

0
No products in the cart.
  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #9656
    blankabctest483
    Member

    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

    #9657
    blankabctest483
    Member

    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

    #9658
    blankabctest483
    Member

    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”.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.