Skip to content

find

general
find all below search path
find /path/to/search
find with max depth
find . -maxdepth 1
find with depth range
find . -mindepth 2 -maxdepth 2
find by name
find . -name "filename"
find by name ignoring case
find . -iname "filename"
find by negated option (-not)
find . -not -name "filename"
find logical or
find . ( -name "*.pdf" -o -name "*.doc" )
find logical and
find . ( -name "*.pdf" -a -not -name "foobar.pdf" )
find by regex
find . -regex ".*/foo/.*.sh"
type/empty/hidden
find by file type
find . -type f      # files
find . -type d      # directories
find empty files
find . -type f -empty
find hidden files
find . -type f -name ".*"
user/group
find by owner
find . -user foobar
find by group
find . -group foobar
permissions
find executable files
find . -type f -executable
find by permissions
find . -perm 755
find executable bit set for others
find . -perm /a=x
find with suid set
find . -perm /u=s`
find . -perm -4000
find with sgid set
find . -perm /g=s
find . -perm -2000
find with sticky bit set
find . -perm -1000
timestamps
find modified last 24 hours ago
find . -mtime 0
find modified exactly/more than/less than 7 days ago
find . -mtime 7
find . -mtime +7
find . -mtime -7
find modified between 7 and 14 days ago
find . -mtime +7 -mtime -14
find accessed last 60 seconds
find . -amin 1
find accessed exactly/more than/less than 10 minutes ago
find . -amin 10
find . -amin +10
find . -amin -10
find accessed between 7 and 14 days ago
find . -atime +7 -atime -14
size
find with size exactly/more than/less than 50MB
find . -size 50M
find . -size +50M
find . -size -50M
execute
find and execute (one command process per file)
find . -exec command {} \;
find and execute (all files as stdin of command)
find . | xargs command
find and delete (always put deletion command at the end of the line!)
find . -type f -name "foobar" -delete
find . -type f -name "foobar" -exec rm {} \;
useful examples
find files older than 14 days and gzip them
find . -mtime +14 -exec gzip {} \;
find and delete files with access time more than a year ago
find . -type f -atime +365 -delete
find dirs and files by permissions
find . -type d -not -perm 700 -o -type f -not -perm 600
find files which were just modified
while true; do find . -type f -mtime -0; done
fix file/directory permissions
find . -type f -perm 0777 -print -exec chmod 644 {} \;
find . -type d -perm 0777 -print -exec chmod 755 {} \;
size of all files bigger than 1G
find . -size +1G -exec du -sh {} \;

last updated: Sat Aug 12 14:29:24 2023

Back to top