Can be OR’d or negated with -o or -not
find -user joe -not -group joe
find -user joe -o -user jane
find -not \( -user joe -o -user jane \)

Can match ownership by name or id
find / -user joe -o -uid 500
Can match octal or symbolic permissions
find -perm 755
matches if mode is exactly 755
find -perm +222
matches if anyone can write
find -perm -222
matches if everyone can write
find -perm -002
matches if other can write

Many find criteria take numeric values
find -size 10M
Files with a size of exactly 10 megabytes
find -size +10M
Files with a size over 10 megabytes
find -size -10M
Files with a size less than 10 megabytes
Other modifiers are available such as k for KB, G for GB, etc.

find can match by inode timestamps
-atime when file was last read
-mtime when file data last changed
-ctime when file data or metadata last changed
Value given is in days
find /tmp -ctime +10
Files changed more than 10 days ago
Can use a value of minutes
-amin
-mmin
-cmin
find /etc -amin -60

Commands can be executed on found files
Command must be preceded with -exec or -ok
-ok prompts before acting on each file
Command must end with Space\;
Can use {} as a filename placeholder
find -size +100M -ok mv {} /tmp/largefiles/ \;

Back up configuration files, adding a .orig extension
$ find -name ‘*.conf’ -exec cp {} {}.orig \;
Prompt to remove Joe’s tmp files that are over 3 days old
$ find /tmp -ctime +3 -user joe -ok rm {} \;
Fix other-writable files in your home directory
$ find ~ -perm -002 -exec chmod o-w {} \;
Do an ls -l style listing of all directories in /home/
$ find /home -type d -ls
Find files that end in .sh but are not executable by anyone. For each file, ask to make it executable by everyone
$ find -not -perm +111 -name ‘*.sh’ -ok chmod 755 {} \;

Leave a Reply

You must be logged in to post a comment.