Index

Table of contents

find

searching

find files
find . -type f
find directories
find . -type d
find files or directories with the given name
find . -name "target"
limit depth of search (1 = direct children)
find . -maxdepth 1
find files modified in the last 90 days
find . -type f -mtime -90
find files modified exactly 90 days ago
find . -type f -mtime 90
find files modified at least 90 days ago
find . -type f -mtime +90

deleting

delete empty files
find /path/to/dir -empty -type f -delete
delete empty directories
find /path/to/dir -empty -type d -delete
delete all files matching a pattern
find . -type f -name "*.log" -delete
delete all directories and their contents matching a pattern(workaround for problem with -exec)
find ./ -name "target" | xargs rm -rf

exec

execute a statement for every file
find . -type f -exec ls -l {} \;
slightly more flexible method
for file in $(find . -type f); do echo "file $file"; done

examples

pack all files older than 14 days
find . -mtime +14 -exec tar --remove-files -czvf {}.tar.gz {} \;
to skip dot files (e.g. .git or .svn) in the root
find *