Find
-print
- Just print the filename
- This is the default action when none is provided
find . -print
find . # same!
-type
file . -type f # file
file . -type d # directory
-name
find . -name notes.txt
find . -iname notes # include name
-delete
# delete files with a name
find . -name "package-lock.json" -type f -delete
# delete empty directories
find . -type d -empty -delete
# delete with a custom command
find . -type d -name ".git" -exec rm -rf {} +
-prune
find . -name "node_modules" -type d -prune # list
find . -name "node_modules" -type d -prune -exec rm -rf "{}" + # delete
-empty
# Find empty directories
find . -type d -empty
-path
- Exclude a path from search
find . -not -path "/home/*" # find everything that is not in the home folder
find . ! -path "/home/*" ! -path "/proc/*" # exclude multiple folders
-nogroup
- Files without group (group has been removed)
-regex
find . -regex ".*\(aaa\|bbb\).*\.so" -exec cp {} {}.bak \;
-exec
cp -p src dest # preserve metadata
chown -R 1000:1000 dest
chmod -R 777 dest # change permissions for everything
find /path/to/directory -type d -exec chmod 700 {} \; # change permissions for folders only
find /path/to/directory -type f -exec chmod 600 {} \; # change permissions for files only