find

Usage

find PATH CONDITIONS ACTIONS

Conditions

search for things that contain ‘.c’

-name "*.c"

search for things owned by user ‘jonathan’

-user jonathan

search for things with no user that corresponds to file’s numeric user ID

-nouser

Search for specific type

search for things that are files

-type f

search for things that are directories

-type d

search for things that are symlinks

-type l

search only 2 folders deep

-maxdepth 2

search with a regex pattern

-regex PATTERN

search for specific file sizes

Exactly 8 512-bit blocks

-size 8

Smaller than 128 bytes

-size -128c

Exactly 1440KiB

-size 1440k

Larger than 10MiB

-size +10M

Larger than 2GiB

-size +2G

search for files modified more recently then file.txt

-newer file.txt

modified newer than file.txt

-newerm file.txt

change, modified, Bcreate

-newerX file.txt

timestamp

-newerXt "1 hour ago"

Actions

execute rm on found items

-exec rm {} \;

print found items

-print

delete found items

-delete

Examples

Find all files ending in ‘.jpg’ and remove them

find . -name '*.jpg' -exec rm {} \;

Find all files created 24 hours ago

find . -newerBt "24 hours ago"

Specific command 1

In the current folder, find files that are readable, executable have a size of 1033 bytes, then send the files found over to cat.

find . -type f -readable ! -executable -size 1033c -exec cat {} \;

Specific command 2

In the current folder, find everything that has a size of 33 bytes, is owned by group bandit6 and user bandit7, redirect errors to /dev/null and send the stuff found over to cat.

find . -size 33c -group bandit6 -user bandit7 2> /dev/null -exec cat {} \;

Also see