find

find


     

  1. Files named filename.suffix
  2. find . -type f -exec grep -ls nohup.out {} \;

     

  3. Greater than or equal to 100KB

  4. find . -size +100k -exec ls -l {} \; | \
    awk '{printf $9, $5}'

     

  5. Greater than or equal to 100KB. Sort the output numerically
  6. find . -size +100k -exec ls -l {} \; | \
    awk '{printf "%40s %10s \n", $9, $5}' | \
    sort -n +1

     

  7. Changed in the last 7 hours
  8. find / -ctime -7 -print

     

  9. Modified in the last 7 hours
  10. find / -daystart -mtime -7 -print

     

  11. Files of type Directory
  12. find . -type d -print

     

  13. Owned by user username
  14. find / -user jdoe -print 2>/dev/null

     

  15. Owned by userid number
  16. find / -uid 227 -print 2>/dev/null

     

  17. Prompt user before removing a file
  18. find / -name nohup.out -ok rm {} \;

     

  19. Case insensitive search
  20. find . -iname -print

     

  21. Find files under current directory named string.scr or string.prt
  22. find . \( -name "*.scr" -o -name "*.rpt" \) -print

     

  23. Find core files. Prompt user for deletion
  24. find / -name core -ok rm {} \;

     

  25. Files that end with 'log'
  26. find / -print 2>/dev/null | \
    grep log\$

     

  27. Files that start with 'law'
  28. find / -print 2>/dev/null | \
    grep \^law

     

  29. Files changed within the last hour
  30. find . -ctime -1 -exec ls -l {} \; 2>/dev/null

     

  31. Files not changed within the last year. Prompt user for deletion
  32. find . -ctime +$(print $((365*20))) -exec ls -l {} \; -ok rm {} \;

     

  33. Symbolic links
  34. find . -type -l -print
    find . -type -l -exec ls -l {} \;

     

  35. Files older than 30 days
  36. cd /var/backup/logs find . -daystart -mtime +30 -print

     

  37. Files older than 30 days. Remove.
  38. find . -daystart -mtime +30 -print -exec rm {} \;

     

  39. Files older than 30 days. Prompt for removal.
  40. find . -daystart -mtime +30 -print -ok rm {} \;

     

  41. Edit all files that contain string
  42. vi `find . -name string -print 2>/dev/null`

     

  43. Changed in the last 20 hours, greater than 1MB in size, excluding some file systems
    1. find . -ctime -20 -size +1000k -print | grep -v \/usr | grep -v \/var | grep -v \/ora