Linux : Awesome commands – find

Name

find — Searching for files and possibly executing commands on them

Synopsis

find [path] [options]

Examples

  • To list all files below a given directory, say /home/user/some-directory

    find /home/user/some-directory

  • To find all pdf files below that directory

    find /home/user/some-directory -name “*.pdf”

  • To find files containing “tutorial” in their name

    find /home/user/some-directory -name “*tutorial*”

  • To find files below the current directory changed in the last 3 days

    find . -ctime -3

  • To find files that haven’t changed in the last 365 days

    find . -ctime +365

  • To find all unreadable files in the current directory

    find . ! -perm +444

  • Same as above, but limit to the current directory and one subdirectory deep

    find . ! -perm +444 -maxdepth 2

  • Make all the files found in the above search readable by user and group (Assumes that you are the owner of all such files or that you are root)

    find . ! -perm +444 -maxdepth 2 -exec chmod ug+r {} ;

  • Two ways of searching for all .c or .h files that contain the string “gtk”. The two methods are equivalent, although xargs has mutliple options that could be used to alter its behavior and thus would be considered the more flexible method.

    grep “gtk” `find . -name *.[ch]`

    find . -name *.[ch] | xargs grep “gtk”

Collected from gnome developer site.

Leave a Reply

Your email address will not be published. Required fields are marked *