Hitchhikers Guide to Computing

becoming a power user ...

Friday, April 18, 2008

a Find FAQ

  1. How do I list all entries under the current directory?

    find .

  2. How do I list all entries under the '/foo/barr' directory?

    find /foo/barr

  3. How do I list all files under the current directory?

    find . -type f

  4. How do I list all files under the '/foo/barr' directory?

    find /foo/barr -type f

  5. How do I list all directories under the current directory?

    find . -type d

  6. How do I list all symlinks under the current directory?

    find . -type l

  7. How do I list all files under the current directory that were modified within the last day?

    find . -type f -mtime -1

  8. How do I list all files under the current directory that were modified within the last 5 days?

    find . -type f -mtime -5

  9. How do I list all files under the current directory that were modified more than 5 days ago?

    find . -type f -mtime +5

  10. How do I list all files under the current directory that start with 'asdf'?

    find . -type f -name "asdf*"

  11. How do I list all files under the current directory that end in '.html'?

    find . -type f -name "*.html"

  12. How do I list all directories under the current directory that start with 'asdf'?

    find . -type d -name "asdf*"

  13. On linux, how do I list all files under the current directory quoted?

    find . -type f -printf '"%p"\n'

  14. On a UNIX without GNU find, how do I list all files under the current directory quoted?

    find . -type f | sed -e 's/^/"/;s/$/"/;'

  15. How do I list all files under the current directory that contain 'ASDF'?

    find . -type f | xargs grep -l 'ASDF'

  16. How do I list all files under the current directory that contain the string 'ASDF' even if the some of the file names have spaces?

    find . -type f -printf '"%p"\n' | xargs grep -l 'ASDF'

  17. How do I list all '.html' files under the current directory that contains 'ASDF'?

    find . -type f -name "*.html" | xargs grep -l 'ASDF'

  18. How do I delete all '.tmp' files under the current directory?

    find . -type f -name "*.tmp" | xargs rm

  19. How do make all files under the current directory world readable?

    find . -type f | xargs chmod +r

  20. How do make all directories under the current directory world searchable?

    find . -type d | xargs chmod +x

  21. How do I list all files that end in '.html' , '.xhtml' or '.txt' under the current directory?

    find . -type f \( -name "*.html" -o -name "*.xhtml" -o -name "*.txt" \)

  22. How do I list all entries that are not symlinks under the current directory?

    find . ! -type l

  23. How do I list all files that do not end in '.html', '.xhtml' and '.txt'?

    find . -type f ! \( -name "*.html" -a -name "*.xhtml" -a -name "*.txt" \)