<s>
In	O
Unix-like	B-Operating_System
and	O
some	O
other	O
operating	B-General_Concept
systems	I-General_Concept
,	O
find	O
is	O
a	O
command-line	B-Device
utility	I-Device
that	O
locates	B-Application
files	B-Operating_System
based	O
on	O
some	O
user-specified	O
criteria	O
and	O
either	O
prints	O
the	O
pathname	O
of	O
each	O
matched	O
object	O
or	O
,	O
if	O
another	O
action	O
is	O
requested	O
,	O
performs	O
that	O
action	O
on	O
each	O
matched	O
object	O
.	O
</s>
<s>
It	O
initiates	O
a	O
search	O
from	O
a	O
desired	O
starting	O
location	O
and	O
then	O
recursively	O
traverses	O
the	O
nodes	B-Data_Structure
(	O
directories	B-Application
)	O
of	O
a	O
hierarchical	O
structure	O
(	O
typically	O
a	O
tree	B-Device
)	O
.	O
</s>
<s>
find	O
can	O
traverse	O
and	O
search	O
through	O
different	O
file	O
systems	O
of	O
partitions	O
belonging	O
to	O
one	O
or	O
more	O
storage	O
devices	O
mounted	O
under	O
the	O
starting	O
directory	B-Application
.	O
</s>
<s>
The	O
possible	O
search	O
criteria	O
include	O
a	O
pattern	B-Language
to	O
match	O
against	O
the	O
filename	B-Device
or	O
a	O
time	O
range	O
to	O
match	O
against	O
the	O
modification	O
time	O
or	O
access	O
time	O
of	O
the	O
file	O
.	O
</s>
<s>
By	O
default	O
,	O
find	O
returns	O
a	O
list	O
of	O
all	O
files	B-Operating_System
below	O
the	O
current	B-Application
working	I-Application
directory	I-Application
,	O
although	O
users	O
can	O
limit	O
the	O
search	O
to	O
any	O
desired	O
maximum	O
number	O
of	O
levels	O
under	O
the	O
starting	O
directory	B-Application
.	O
</s>
<s>
The	O
related	O
locate	B-Application
programs	O
use	O
a	O
database	O
of	O
indexed	O
files	B-Operating_System
obtained	O
through	O
find	O
(	O
updated	O
at	O
regular	O
intervals	O
,	O
typically	O
by	O
cron	B-General_Concept
job	I-General_Concept
)	O
to	O
provide	O
a	O
faster	O
method	O
of	O
searching	O
the	O
entire	O
file	O
system	O
for	O
files	B-Operating_System
by	O
name	O
.	O
</s>
<s>
find	O
appeared	O
in	O
Version	B-Operating_System
5	I-Operating_System
Unix	I-Operating_System
as	O
part	O
of	O
the	O
Programmer	B-Operating_System
's	I-Operating_System
Workbench	I-Operating_System
project	O
,	O
and	O
was	O
written	O
by	O
Dick	O
Haight	O
alongside	O
cpio	B-Application
,	O
which	O
were	O
designed	O
to	O
be	O
used	O
together	O
.	O
</s>
<s>
The	O
GNU	B-Application
find	I-Application
implementation	O
was	O
originally	O
written	O
by	O
Eric	O
Decker	O
.	O
</s>
<s>
The	O
command	B-Application
has	O
also	O
been	O
ported	O
to	O
the	O
IBM	B-Application
i	I-Application
operating	B-General_Concept
system	I-General_Concept
.	O
</s>
<s>
The	O
two	O
options	O
control	O
how	O
the	O
find	O
command	B-Application
should	O
treat	O
symbolic	B-Application
links	I-Application
.	O
</s>
<s>
The	O
default	O
behaviour	O
is	O
never	O
to	O
follow	O
symbolic	B-Application
links	I-Application
.	O
</s>
<s>
The	O
flag	O
will	O
cause	O
the	O
find	O
command	B-Application
to	O
follow	O
symbolic	B-Application
links	I-Application
.	O
</s>
<s>
The	O
flag	O
will	O
only	O
follow	O
symbolic	B-Application
links	I-Application
while	O
processing	O
the	O
command	B-Application
line	O
arguments	O
.	O
</s>
<s>
A	O
common	O
extension	O
is	O
the	O
flag	O
,	O
for	O
explicitly	O
disabling	O
symlink	B-Application
following	O
.	O
</s>
<s>
find	O
is	O
capable	O
of	O
interpreting	O
wildcards	B-Algorithm
internally	O
and	O
commands	O
must	O
be	O
quoted	O
carefully	O
in	O
order	O
to	O
control	O
shell	B-Language
globbing	I-Language
.	O
</s>
<s>
Expression	O
elements	O
are	O
separated	O
by	O
the	O
command-line	O
argument	O
boundary	O
,	O
usually	O
represented	O
as	O
whitespace	O
in	O
shell	B-Operating_System
syntax	O
.	O
</s>
<s>
GNU	B-Application
find	I-Application
has	O
a	O
large	O
number	O
of	O
additional	O
features	O
not	O
specified	O
by	O
POSIX	O
.	O
</s>
<s>
-name	O
pattern	B-Language
:	O
tests	O
whether	O
the	O
file	O
name	O
matches	O
the	O
shell-glob	O
pattern	B-Language
given	O
.	O
</s>
<s>
Unix	B-Application
file	I-Application
types	I-Application
accepted	O
include	O
:	O
</s>
<s>
d	O
:	O
directory	B-Application
;	O
</s>
<s>
l	O
:	O
symbolic	B-Application
link	I-Application
;	O
</s>
<s>
p	O
:	O
named	B-Operating_System
pipe	I-Operating_System
;	O
</s>
<s>
s	O
:	O
socket	B-Protocol
;	O
</s>
<s>
D	O
:	O
door	B-General_Concept
.	O
</s>
<s>
-exec	O
program	O
[	O
argument	O
...	O
]	O
;	O
:	O
always	O
returns	O
true	O
;	O
run	O
a	O
program	O
with	O
the	O
fixed	O
arguments	O
given	O
and	O
the	O
current	O
path	O
of	O
the	O
file	O
.	O
</s>
<s>
-exec	O
program	O
[	O
argument	O
...	O
]	O
 {  } 	O
+	O
:	O
always	O
returns	O
true	O
;	O
run	O
a	O
program	O
with	O
the	O
fixed	O
arguments	O
given	O
and	O
as	O
many	O
paths	O
as	O
possible	O
(	O
up	O
to	O
the	O
maximum	O
command-line	O
size	O
,	O
like	O
xargs	B-Application
)	O
.	O
</s>
<s>
-ok	O
program	O
[	O
argument	O
...	O
]	O
;	O
:	O
like	O
-exec	O
,	O
but	O
returns	O
true	O
or	O
false	O
depending	O
on	O
whether	O
the	O
program	O
returns	O
0	O
.	O
</s>
<s>
Operators	O
can	O
be	O
used	O
to	O
enhance	O
the	O
expressions	O
of	O
the	O
find	O
command	B-Application
.	O
</s>
<s>
This	O
command	B-Application
searches	O
the	O
current	B-Application
working	I-Application
directory	I-Application
tree	B-Device
for	O
files	B-Operating_System
whose	O
names	O
start	O
with	O
or	O
.	O
</s>
<s>
We	O
quote	O
the	O
so	O
that	O
the	O
shell	B-Operating_System
does	O
not	O
expand	O
it	O
.	O
</s>
<s>
This	O
command	B-Application
searches	O
the	O
current	B-Application
working	I-Application
directory	I-Application
tree	B-Device
except	O
the	O
subdirectory	B-Application
tree	B-Device
"	O
.svn	O
"	O
for	O
files	B-Operating_System
whose	O
name	O
is	O
"	O
foo.cpp	O
"	O
.	O
</s>
<s>
so	O
that	O
it	O
's	O
not	O
interpreted	O
by	O
the	O
shell	B-Operating_System
as	O
the	O
history	O
substitution	O
character	O
.	O
</s>
<s>
Real-world	O
file	O
systems	O
often	O
contain	O
looped	O
structures	O
created	O
through	O
the	O
use	O
of	O
hard	B-Application
or	O
soft	B-Application
links	I-Application
.	O
</s>
<s>
This	O
searches	O
the	O
current	B-Application
working	I-Application
directory	I-Application
tree	B-Device
for	O
files	B-Operating_System
whose	O
names	O
start	O
with	O
my	O
.	O
</s>
<s>
The	O
single	O
quotes	O
avoid	O
the	O
shell	B-Operating_System
expansion	O
—	O
without	O
them	O
the	O
shell	B-Operating_System
would	O
replace	O
my*	O
with	O
the	O
list	O
of	O
files	B-Operating_System
whose	O
names	O
begin	O
with	O
my	O
in	O
the	O
current	B-Application
working	I-Application
directory	I-Application
.	O
</s>
<s>
In	O
newer	O
versions	O
of	O
the	O
program	O
,	O
the	O
directory	B-Application
may	O
be	O
omitted	O
,	O
and	O
it	O
will	O
imply	O
the	O
current	B-Application
working	I-Application
directory	I-Application
.	O
</s>
<s>
This	O
limits	O
the	O
results	O
of	O
the	O
above	O
search	O
to	O
only	O
regular	O
files	B-Operating_System
,	O
therefore	O
excluding	O
directories	B-Application
,	O
special	B-Application
files	I-Application
,	O
symbolic	B-Application
links	I-Application
,	O
etc	O
.	O
</s>
<s>
my*	O
is	O
enclosed	O
in	O
single	O
quotes	O
(	O
apostrophes	O
)	O
as	O
otherwise	O
the	O
shell	B-Operating_System
would	O
replace	O
it	O
with	O
the	O
list	O
of	O
files	B-Operating_System
in	O
the	O
current	B-Application
working	I-Application
directory	I-Application
starting	O
with	O
my	O
…	O
</s>
<s>
(	O
Note	O
that	O
early	O
versions	O
of	O
the	O
find	O
command	B-Application
had	O
no	O
default	O
action	O
at	O
all	O
;	O
therefore	O
the	O
resulting	O
list	O
of	O
files	B-Operating_System
would	O
be	O
discarded	O
,	O
to	O
the	O
bewilderment	O
of	O
users	O
.	O
)	O
</s>
<s>
This	O
searches	O
every	O
directory	B-Application
for	O
a	O
regular	O
file	O
whose	O
name	O
is	O
myfile	O
and	O
prints	O
it	O
to	O
the	O
screen	O
.	O
</s>
<s>
It	O
is	O
generally	O
not	O
a	O
good	O
idea	O
to	O
look	O
for	O
files	B-Operating_System
this	O
way	O
.	O
</s>
<s>
This	O
can	O
take	O
a	O
considerable	O
amount	O
of	O
time	O
,	O
so	O
it	O
is	O
best	O
to	O
specify	O
the	O
directory	B-Application
more	O
precisely	O
.	O
</s>
<s>
Some	O
operating	B-General_Concept
systems	I-General_Concept
may	O
mount	O
dynamic	O
file	O
systems	O
that	O
are	O
not	O
congenial	O
to	O
find	O
.	O
</s>
<s>
More	O
complex	O
filenames	B-Device
including	O
characters	O
special	O
to	O
the	O
shell	B-Operating_System
may	O
need	O
to	O
be	O
enclosed	O
in	O
single	O
quotes	O
.	O
</s>
<s>
This	O
searches	O
every	O
directory	B-Application
except	O
the	O
subdirectory	B-Application
tree	B-Device
excluded_path	O
(	O
full	O
path	O
including	O
the	O
leading	O
/	O
)	O
that	O
is	O
pruned	O
by	O
the	O
-prune	O
action	O
,	O
for	O
a	O
regular	O
file	O
whose	O
name	O
is	O
myfile	O
.	O
</s>
<s>
This	O
searches	O
the	O
/home/weedly	O
directory	B-Application
tree	I-Application
for	O
regular	O
files	B-Operating_System
named	O
myfile	O
.	O
</s>
<s>
You	O
should	O
always	O
specify	O
the	O
directory	B-Application
to	O
the	O
deepest	O
level	O
you	O
can	O
remember	O
.	O
</s>
<s>
This	O
searches	O
the	O
local	O
subdirectory	B-Application
tree	B-Device
of	O
the	O
current	B-Application
working	I-Application
directory	I-Application
and	O
the	O
/tmp	O
directory	B-Application
tree	I-Application
for	O
directories	B-Application
named	O
mydir	O
.	O
</s>
<s>
Since	O
errors	O
are	O
printed	O
to	O
stderr	O
,	O
they	O
can	O
be	O
suppressed	O
by	O
redirecting	O
the	O
output	O
to	O
/dev/null	B-Operating_System
.	O
</s>
<s>
The	O
following	O
example	O
shows	O
how	O
to	O
do	O
this	O
in	O
the	O
bash	O
shell	B-Operating_System
:	O
</s>
<s>
If	O
you	O
are	O
a	O
csh	B-Operating_System
or	O
tcsh	B-Language
user	O
,	O
you	O
cannot	O
redirect	O
stderr	O
without	O
redirecting	O
stdout	O
as	O
well	O
.	O
</s>
<s>
You	O
can	O
use	O
sh	O
to	O
run	O
the	O
find	O
command	B-Application
to	O
get	O
around	O
this	O
:	O
</s>
<s>
An	O
alternate	O
method	O
when	O
using	O
csh	B-Operating_System
or	O
tcsh	B-Language
is	O
to	O
pipe	O
the	O
output	O
from	O
stdout	O
and	O
stderr	O
into	O
a	O
grep	B-Application
command	B-Application
.	O
</s>
<s>
In	O
many	O
shells	O
the	O
parentheses	O
must	O
be	O
escaped	O
with	O
a	O
backslash	O
(	O
\( 	O
and	O
\	O
)	O
)	O
to	O
prevent	O
them	O
from	O
being	O
interpreted	O
as	O
special	O
shell	B-Operating_System
characters	O
.	O
</s>
<s>
This	O
command	B-Application
changes	O
the	O
permissions	O
of	O
all	O
regular	O
files	B-Operating_System
whose	O
names	O
end	O
with	O
.mp3	O
in	O
the	O
directory	B-Application
tree	I-Application
/var/ftp/mp3	O
.	O
</s>
<s>
The	O
action	O
is	O
carried	O
out	O
by	O
specifying	O
the	O
statement	O
-exec	O
chmod	B-Application
644	O
 {  } 	O
\	O
;	O
in	O
the	O
command	B-Application
.	O
</s>
<s>
For	O
every	O
regular	O
file	O
whose	O
name	O
ends	O
in	O
.mp3	O
,	O
the	O
command	B-Application
chmod	B-Application
644	O
 {  } 	O
is	O
executed	O
replacing	O
 {  } 	O
with	O
the	O
name	O
of	O
the	O
file	O
.	O
</s>
<s>
The	O
semicolon	O
(	O
backslashed	O
to	O
avoid	O
the	O
shell	B-Operating_System
interpreting	O
it	O
as	O
a	O
command	B-Application
separator	O
)	O
indicates	O
the	O
end	O
of	O
the	O
command	B-Application
.	O
</s>
<s>
If	O
you	O
will	O
be	O
executing	O
over	O
many	O
results	O
,	O
it	O
is	O
more	O
efficient	O
to	O
use	O
a	O
variant	O
of	O
the	O
exec	O
primary	O
that	O
collects	O
filenames	B-Device
up	O
to	O
and	O
then	O
executes	O
COMMAND	B-Application
with	O
a	O
list	O
of	O
filenames	B-Device
.	O
</s>
<s>
This	O
will	O
ensure	O
that	O
filenames	B-Device
with	O
whitespaces	O
are	O
passed	O
to	O
the	O
executed	O
without	O
being	O
split	O
up	O
by	O
the	O
shell	B-Operating_System
.	O
</s>
<s>
The	O
-delete	O
action	O
is	O
a	O
GNU	B-Application
extension	O
,	O
and	O
using	O
it	O
turns	O
on	O
-depth	O
.	O
</s>
<s>
So	O
,	O
if	O
you	O
are	O
testing	O
a	O
find	O
command	B-Application
with	O
-print	O
instead	O
of	O
-delete	O
in	O
order	O
to	O
figure	O
out	O
what	O
will	O
happen	O
before	O
going	O
for	O
it	O
,	O
you	O
need	O
to	O
use	O
-depth	O
-print	O
.	O
</s>
<s>
Delete	O
empty	O
files	B-Operating_System
and	O
print	O
the	O
names	O
(	O
note	O
that	O
-empty	O
is	O
a	O
vendor	O
unique	O
extension	O
from	O
GNU	B-Application
find	I-Application
that	O
may	O
not	O
be	O
available	O
in	O
all	O
find	O
implementations	O
)	O
:	O
</s>
<s>
Delete	O
empty	O
regular	O
files	B-Operating_System
:	O
</s>
<s>
Delete	O
empty	O
directories	B-Application
:	O
</s>
<s>
Delete	O
empty	O
files	B-Operating_System
named	O
'	O
bad	O
 '	O
:	O
</s>
<s>
This	O
command	B-Application
will	O
search	O
all	O
files	B-Operating_System
from	O
the	O
/tmp	O
directory	B-Application
tree	I-Application
for	O
a	O
string	O
:	O
</s>
<s>
The	O
/dev/null	B-Operating_System
argument	O
is	O
used	O
to	O
show	O
the	O
name	O
of	O
the	O
file	O
before	O
the	O
text	O
that	O
is	O
found	O
.	O
</s>
<s>
(	O
Alternatively	O
,	O
some	O
versions	O
of	O
grep	B-Application
support	O
a	O
flag	O
that	O
forces	O
the	O
file	O
name	O
to	O
be	O
printed	O
.	O
)	O
</s>
<s>
GNU	B-Application
grep	B-Application
can	O
be	O
used	O
on	O
its	O
own	O
to	O
perform	O
this	O
task	O
:	O
</s>
<s>
Example	O
of	O
search	O
for	O
"	O
LOG	O
"	O
in	O
jsmith	O
's	O
home	O
directory	B-Application
tree	I-Application
:	O
</s>
<s>
Example	O
of	O
search	O
for	O
the	O
string	O
"	O
ERROR	O
"	O
in	O
all	O
XML	O
files	B-Operating_System
in	O
the	O
current	B-Application
working	I-Application
directory	I-Application
tree	B-Device
:	O
</s>
<s>
Note	O
with	O
more	O
complex	O
text	O
(	O
notably	O
in	O
most	O
popular	O
shells	O
descended	O
from	O
`sh`	O
and	O
`csh`	O
)	O
single	O
quotes	O
are	O
often	O
the	O
easier	O
choice	O
,	O
since	O
double	O
quotes	O
do	O
not	O
prevent	O
all	O
special	O
interpretation	O
.	O
</s>
<s>
Quoting	O
filenames	B-Device
which	O
have	O
English	O
contractions	O
demonstrates	O
how	O
this	O
can	O
get	O
rather	O
complicated	O
,	O
since	O
a	O
string	O
with	O
an	O
apostrophe	O
in	O
it	O
is	O
easier	O
to	O
protect	O
with	O
double	O
quotes	O
:	O
</s>
<s>
Searching	O
files	B-Operating_System
whose	O
size	O
is	O
between	O
100	O
kilobytes	O
and	O
500	O
kilobytes	O
:	O
</s>
<s>
Searching	O
empty	O
files	B-Operating_System
:	O
</s>
<s>
Searching	O
non-empty	O
files	B-Operating_System
:	O
</s>
<s>
This	O
command	B-Application
will	O
search	O
the	O
/usr/src	O
directory	B-Application
tree	I-Application
.	O
</s>
<s>
All	O
files	B-Operating_System
that	O
are	O
of	O
the	O
form	O
and	O
are	O
excluded	O
.	O
</s>
<s>
The	O
size	O
does	O
not	O
count	O
indirect	O
blocks	O
,	O
but	O
it	O
does	O
count	O
blocks	O
in	O
sparse	O
files	B-Operating_System
that	O
are	O
not	O
actually	O
allocated	O
.	O
</s>
<s>
Date	O
ranges	O
can	O
be	O
used	O
to	O
,	O
for	O
example	O
,	O
list	O
files	B-Operating_System
changed	O
since	O
a	O
backup	O
.	O
</s>
<s>
Files	B-Operating_System
modified	O
a	O
relative	O
number	O
of	O
days	O
ago	O
:	O
</s>
<s>
Example	O
to	O
find	O
all	O
text	O
files	B-Operating_System
in	O
the	O
document	O
folder	O
modified	O
since	O
a	O
week	O
(	O
meaning	O
7	O
days	O
)	O
:	O
</s>
<s>
Files	B-Operating_System
modified	O
before	O
or	O
after	O
an	O
absolute	O
date	O
and	O
time	O
:	O
</s>
<s>
Example	O
to	O
find	O
all	O
text	O
files	B-Operating_System
last	O
edited	O
in	O
February	O
2017	O
:	O
</s>
<s>
List	O
all	O
text	O
files	B-Operating_System
edited	O
more	O
recently	O
than	O
"	O
document.txt	O
"	O
:	O
</s>
<s>
locate	B-Application
is	O
a	O
Unix	B-Application
search	O
tool	O
that	O
searches	O
a	O
prebuilt	O
database	O
of	O
files	B-Operating_System
instead	O
of	O
directory	B-Application
trees	I-Application
of	O
a	O
file	O
system	O
.	O
</s>
<s>
grep	B-Application
is	O
a	O
command-line	B-Device
utility	I-Device
for	O
searching	O
plain-text	O
data	O
sets	O
for	O
lines	O
matching	O
a	O
regular	O
expression	O
and	O
by	O
default	O
reporting	O
matching	O
lines	O
on	O
standard	O
output	O
.	O
</s>
<s>
tree	B-Device
is	O
a	O
command-line	B-Device
utility	I-Device
that	O
recursively	O
lists	O
files	B-Operating_System
found	O
in	O
a	O
directory	B-Application
tree	I-Application
,	O
indenting	O
the	O
filenames	B-Device
according	O
to	O
their	O
position	O
in	O
the	O
file	O
hierarchy	O
.	O
</s>
<s>
GNU	B-Application
Find	I-Application
Utilities	I-Application
(	O
also	O
known	O
as	O
findutils	B-Application
)	O
is	O
a	O
GNU	B-Application
package	I-Application
which	O
contains	O
implementations	O
of	O
the	O
tools	O
find	O
and	O
xargs	B-Application
.	O
</s>
<s>
BusyBox	B-Application
is	O
a	O
utility	O
that	O
provides	O
several	O
stripped-down	O
Unix	B-Application
tools	I-Application
in	O
a	O
single	O
executable	O
file	O
,	O
intended	O
for	O
embedded	O
operating	B-General_Concept
systems	I-General_Concept
with	O
very	O
limited	O
resources	O
.	O
</s>
<s>
dir	B-Device
has	O
the	O
/s	O
option	O
that	O
recursively	O
searches	O
for	O
files	B-Operating_System
or	O
directories	B-Application
.	O
</s>
<s>
Plan	B-Operating_System
9	I-Operating_System
from	I-Operating_System
Bell	I-Operating_System
Labs	I-Operating_System
uses	O
two	O
utilities	O
to	O
replace	O
:	O
a	O
that	O
only	O
walks	O
the	O
tree	B-Device
and	O
prints	O
the	O
names	O
and	O
a	O
that	O
only	O
filters	O
(	O
like	O
grep	B-Application
)	O
by	O
evaluating	O
expressions	O
in	O
the	O
form	O
of	O
a	O
shell	B-Operating_System
script	O
.	O
</s>
<s>
The	O
commands	O
are	O
not	O
part	O
of	O
Plan	B-Application
9	I-Application
from	I-Application
User	I-Application
Space	I-Application
,	O
so	O
Google	O
's	O
Benjamin	O
Barenblat	O
has	O
a	O
ported	O
version	O
to	O
POSIX	O
systems	O
available	O
through	O
GitHub	O
.	O
</s>
<s>
is	O
a	O
simple	O
alternative	O
to	O
written	O
in	O
the	O
Rust	B-Application
programming	I-Application
language	I-Application
.	O
</s>
