Some find commands

Some quick find examples

 

find in current directory all files that have size greater than 0

  • find . -type f -size +1 -exec ls -la {} \;

 

find in current directory all files that have size less than or equal to 0

  • find . -type f -size -1 -exec ls -la {} \;

 

find in current directory all files that have size less than or equal to 0, then remove them

  • find . -type f -size -1 -exec rm {} \;

 

find a file that is exactly 5 days old

  • find . -type f  -mtime 5 -ls
  • find . -type f  -mtime 5 -exec ls -la {} \;

 

find a file that is 4 to 9 days old

  • find . -type f  -mtime +3 -mtime -10  -ls

 

find  a file that is exactly 5 days old, then remove it

  • find . -type f  -mtime 5 -ls
  • find . -type f  -mtime 5 -exec rm {} \;

 

find by different types.  This is not a complete list:

  • find . -type f -print
  • find . -type l -print
f file
d directory
l symbolic link
b block device file
c character device file

 

Permanent link to this article: https://daherlabs.mywire.org/wordpress/?p=237

Leave a Reply

Your email address will not be published.