1find(1)                          User Commands                         find(1)
2
3
4

NAME

6       find - find files
7

SYNOPSIS

9       /usr/bin/find [-H | -L] path... expression
10
11
12       /usr/xpg4/bin/find [-H | -L] path... expression
13
14

DESCRIPTION

16       The  find utility recursively descends the directory hierarchy for each
17       path seeking files that match a Boolean expression written in the  pri‐
18       maries specified below.
19
20
21       find  is  able  to  descend to arbitrary depths in a file hierarchy and
22       does not fail due to path length limitations  (unless  a  path  operand
23       specified by the application exceeds PATH_MAX requirements).
24
25
26       find  detects  infinite  loops;  that is, entering a previously visited
27       directory that is an ancestor of the last file encountered.
28

OPTIONS

30       The following options are supported:
31
32       -H    Causes the file information and file type evaluated for each sym‐
33             bolic  link  encountered  on  the command line to be those of the
34             file referenced by the link, and not the link itself. If the ref‐
35             erenced file does not exist, the file information and type is for
36             the link itself. File information for all symbolic links  not  on
37             the command line is that of the link itself.
38
39
40       -L    Causes the file information and file type evaluated for each sym‐
41             bolic link to be those of the file referenced by  the  link,  and
42             not the link itself. See NOTES.
43
44
45
46       Specifying  more than one of the mutually-exclusive options -H and -Lis
47       not considered an error.  The  last  option  specified  determines  the
48       behavior of the utility.
49

OPERANDS

51       The following operands are supported:
52
53       path          A  pathname  of a starting point in the directory hierar‐
54                     chy.
55
56
57       expression    The first argument that starts with a , or is a !  or  a
58                     (,  and  all  subsequent  arguments are interpreted as an
59                     expression made up of the following primaries and  opera‐
60                     tors.  In  the descriptions, wherever n is used as a pri‐
61                     mary argument, it is interpreted  as  a  decimal  integer
62                     optionally  preceded  by a plus (+) or minus () sign, as
63                     follows:
64
65                     +n    more than n
66
67
68                     n     exactly n
69
70
71                     -n    less than n
72
73
74
75   Expressions
76       Valid expressions are:
77
78       -acl             True if the file have additional ACLs defined.
79
80
81       -amin n          File was last accessed n minutes ago.
82
83
84       -atime n         True if the file was accessed n days ago.  The  access
85                        time of directories in path is changed by find itself.
86
87
88       -cmin n          File's status was last changed n minutes ago.
89
90
91       -cpio device     Always true. Writes the current file on device in cpio
92                        format (5120-byte records).
93
94
95       -ctime n         True if the file's status was changed n days ago.
96
97
98       -depth           Always true. Causes descent of the directory hierarchy
99                        to  be  done  so  that  all entries in a directory are
100                        acted on before the directory itself. This can be use‐
101                        ful  when  find is used with cpio(1) to transfer files
102                        that are contained in directories without  write  per‐
103                        mission.
104
105
106       -exec command    True  if  the executed command returns a zero value as
107                        exit status. The end of command must be punctuated  by
108                        an  escaped  semicolon  (;).  A command argument {} is
109                        replaced by the current pathname. If the last argument
110                        to -exec is {} and you specify + rather than the semi‐
111                        colon (;), the command is invoked fewer times, with {}
112                        replaced  by groups of pathnames. If any invocation of
113                        the command returns a non-zero value as  exit  status,
114                        find returns a non-zero exit status.
115
116
117       -follow          Always  true  and  always evaluated no matter where it
118                        appears in expression. The behavior is unspecified  if
119                        -follow  is used when the find command is invoked with
120                        either the -H or the -L option. Causes symbolic  links
121                        to  be  followed.  When following symbolic links, find
122                        keeps track of the directories visited so that it  can
123                        detect  infinite loops. For example, such a loop would
124                        occur if a symbolic link pointed to an ancestor.  This
125                        expression  should  not  be  used with the find-type l
126                        expression. See NOTES.
127
128
129       -fstype type     True if the filesystem to which the file belongs is of
130                        type type.
131
132
133       -group gname     True  if the file belongs to the group gname. If gname
134                        is numeric and does not appear in the /etc/group file,
135                        or in the NIS/NIS+ tables, it is taken as a group ID.
136
137
138       -inum n          True if the file has inode number n.
139
140
141       -links n         True if the file has n links.
142
143
144       -local           True if the file system type is not a remote file sys‐
145                        tem type as defined in the /etc/dfs/fstypes file.  nfs
146                        is  used  as the default remote filesystem type if the
147                        /etc/dfs/fstypes  file  is  not  present.  The  -local
148                        option  descends  the  hierarchy of non-local directo‐
149                        ries. See EXAMPLES for an example of how to search for
150                        local files without descending.
151
152
153       -ls              Always true. Prints current pathname together with its
154                        associated statistics. These include (respectively):
155
156                            o      inode number
157
158                            o      size in kilobytes (1024 bytes)
159
160                            o      protection mode
161
162                            o      number of hard links
163
164                            o      user
165
166                            o      group
167
168                            o      size in bytes
169
170                            o      modification time.
171                        If the file is a special file, the size field  instead
172                        contains the major and minor device numbers.
173
174                        If  the  file  is a symbolic link, the pathname of the
175                        linked-to file is printed preceded by `'. The  format
176                        is identical to that of ls -gilds (see ls(1B)).
177
178                        Formatting  is  done internally, without executing the
179                        ls program.
180
181
182       -mmin n          File's data was last modified n minutes ago.
183
184
185       -mount           Always true. Restricts the search to the  file  system
186                        containing  the  directory  specified.  Does  not list
187                        mount points to other file systems.
188
189
190       -mtime n         True if the file's data was modified n days ago.
191
192
193       -name pattern    True if pattern matches the basename  of  the  current
194                        file  name.  Normal shell file name generation charac‐
195                        ters (see sh(1)) can be used. A backslash (\) is  used
196                        as an escape character within the pattern. The pattern
197                        should be escaped or quoted when find is invoked  from
198                        the shell.
199
200                        Unless  the  character  '.' is explicitly specified in
201                        the beginning of pattern, a current file  name  begin‐
202                        ning  with  '.'  does  not  match  pattern  when using
203                        /usr/bin/find. /usr/xpg4/bin/find does not  make  this
204                        distinction;  wildcard file name generation characters
205                        can match file names beginning with '.'.
206
207
208       -ncpio device    Always true. Writes the current file on device in cpio
209                        -c format (5120 byte records).
210
211
212       -newer file      True  if  the  current  file  has  been  modified more
213                        recently than the argument file.
214
215
216       -nogroup         True if the  file  belongs  to  a  group  not  in  the
217                        /etc/group file, or in the NIS/NIS+ tables.
218
219
220       -nouser          True  if  the  file  belongs  to  a  user  not  in the
221                        /etc/passwd file, or in the NIS/NIS+ tables.
222
223
224       -ok command      Like -exec, except that the generated command line  is
225                        printed  with  a  question mark first, and is executed
226                        only if the response is affirmative.
227
228
229       -perm [-]mode    The mode argument is used to represent file mode bits.
230                        It  is  identical in format to the symbolic mode oper‐
231                        and, symbolic_mode_list, described in chmod(1), and is
232                        interpreted  as  follows.  To  start,  a  template  is
233                        assumed with all file mode bits cleared. An op  symbol
234                        of:
235
236                        +       Set the appropriate mode bits in the template
237
238
239                        Clear the appropriate bits
240
241
242                        =       Set  the appropriate mode bits, without regard
243                                to the contents of the file mode creation mask
244                                of the process
245
246                        The  op  symbol  of cannot be the first character of
247                        mode, to avoid ambiguity  with  the  optional  leading
248                        hyphen.  Since the initial mode is all bits off, there
249                        are no symbolic modes that need to use as the  first
250                        character.
251
252                        If  the  hyphen  is  omitted, the primary evaluates as
253                        true when the file permission bits exactly  match  the
254                        value of the resulting template.
255
256                        Otherwise,  if  mode is prefixed by a hyphen, the pri‐
257                        mary evaluates as true if at least all the bits in the
258                        resulting  template  are  set  in  the file permission
259                        bits.
260
261
262       -perm [-]onum    True if the file permission flags  exactly  match  the
263                        octal  number onum (see chmod(1)). If onum is prefixed
264                        by a minus sign (), only the bits  that  are  set  in
265                        onum  are compared with the file permission flags, and
266                        the expression evaluates true if they match.
267
268
269       -print           Always  true.  Causes  the  current  pathname  to   be
270                        printed.
271
272
273       -prune           Always  yields  true. Does not examine any directories
274                        or files in the directory structure below the  pattern
275                        just  matched. (See EXAMPLES). If -depth is specified,
276                        -prune has no effect.
277
278
279       -size n[c]       True if the file is  n  blocks  long  (512  bytes  per
280                        block). If n is followed by a c, the size is in bytes.
281
282
283       -type c          True if the type of the file is c, where c is b, c, d,
284                        D, f, l, p, or s for  block  special  file,  character
285                        special  file,  directory,  door, plain file, symbolic
286                        link, fifo (named pipe), or socket, respectively.
287
288
289       -user uname      True if the file belongs to the user uname.  If  uname
290                        is  numeric and does not appear as a login name in the
291                        /etc/passwd file, or in the  NIS/NIS+  tables,  it  is
292                        taken as a user ID.
293
294
295       -xdev            Same as the -mount primary.
296
297
298       -xattr           True if the file has extended attributes.
299
300
301   Complex Expressions
302       The  primaries  can be combined using the following operators (in order
303       of decreasing precedence):
304
305       1)(expression)
306
307           True if the parenthesized expression is true (parentheses are  spe‐
308           cial to the shell and must be escaped).
309
310
311       2)!expression
312
313           The negation of a primary (! is the unary not operator).
314
315
316       3) expression[-a] expression
317
318           Concatenation  of  primaries  (the  and operation is implied by the
319           juxtaposition of two primaries).
320
321
322       4) expression-oexpression
323
324           Alternation of primaries (-o is the or operator).
325
326
327
328       When you use find in conjunction with cpio, if you use  the  -L  option
329       with  cpio,  you  must  use the -L option or the -follow primitive with
330       find and vice versa. Otherwise the results are unspecified.
331
332
333       If no expression is present, -print is used as the  expression.  Other‐
334       wise, if the specified expression does not contain any of the primaries
335       -exec, -ok, -ls, or -print, the  specified  expression  is  effectively
336       replaced by:
337
338
339       (specified) -print
340
341
342       The  -user, -group, and -newer primaries each evaluate their respective
343       arguments only once. Invocation of command specified by  -exec  or  -ok
344       does not affect subsequent primaries on the same file.
345

USAGE

347       See  largefile(5)  for  the  description  of  the behavior of find when
348       encountering files greater than or equal to 2 Gbyte (2^31 bytes).
349

EXAMPLES

351       Example 1 Writing Out the Hierarchy Directory
352
353
354       The following commands are equivalent:
355
356
357         example% find .
358         example% find . -print
359
360
361
362
363       They both write out the entire directory  hierarchy  from  the  current
364       directory.
365
366
367       Example 2 Removing Files
368
369
370       The  following  comand  removes  all files in your home directory named
371       a.out or *.o that have not been accessed for a week:
372
373
374         example% find $HOME \( -name a.out -o -name '*.o' \) \
375                -atime +7 -exec rm {} \;
376
377
378
379       Example 3 Printing All File Names But Skipping SCCS Directories
380
381
382       The following command recursively print all file names in  the  current
383       directory and below, but skipping SCCS directories:
384
385
386         example% find . -name SCCS -prune -o -print
387
388
389
390       Example 4 Printing all file names and the SCCS directory name
391
392
393       Recursively  print  all  file names in the current directory and below,
394       skipping the contents of SCCS directories, but printing  out  the  SCCS
395       directory name:
396
397
398         example% find . -print -name SCCS -prune
399
400
401
402       Example 5 Testing for the Newer File
403
404
405       The  following  command is basically equivalent to the -nt extension to
406       test(1):
407
408
409         example$ if [ -n "$(find
410         file1 -prune -newer file2)" ]; then
411
412         printf %s\\n "file1 is newer than file2"
413
414
415
416       Example 6 Selecting a File Using 24-hour Mode
417
418
419       The descriptions of -atime, -ctime, and -mtime use  the  terminology  n
420       ``24-hour  periods''. For example, a file accessed at 23:59 is selected
421       by:
422
423
424         example% find . -atime -1 -print
425
426
427
428
429       at 00:01 the next day (less than 24 hours later, not more than one  day
430       ago).  The  midnight boundary between days has no effect on the 24-hour
431       calculation.
432
433
434       Example 7 Printing Files Matching a User's Permission Mode
435
436
437       The following command recursively print all file names whose permission
438       mode exactly matches read, write, and execute access for user, and read
439       and execute access for group and other:
440
441
442         example% find . -perm u=rwx,g=rx,o=rx
443
444
445
446
447       The above could alternatively be specified as follows:
448
449
450         example% find . -perm a=rwx,g-w,o-w
451
452
453
454       Example 8 Printing Files with Write Access for other
455
456
457       The following command recursively print all file names whose permission
458       includes, but is not limited to, write access for other:
459
460
461         example% find . -perm -o+w
462
463
464
465       Example 9 Printing Local Files without Descending Non-local Directories
466
467         example% find . ! -local -prune -o -print
468
469
470
471       Example  10  Printing  the  Files in the Name Space Possessing Extended
472       Attributes
473
474         example% find . -xattr
475
476
477

ENVIRONMENT VARIABLES

479       See environ(5) for descriptions of the following environment  variables
480       that  affect the execution of find: LANG, LC_ALL, LC_COLLATE, LC_CTYPE,
481       LC_MESSAGES, and NLSPATH.
482
483       PATH    Determine the location of the utility_name for  the  -exec  and
484               -ok primaries.
485
486
487
488       Affirmative  responses are processed using the extended regular expres‐
489       sion defined for the yesexpr keyword in the LC_MESSAGES category of the
490       user's  locale. The locale specified in the LC_COLLATE category defines
491       the behavior of ranges, equivalence classes, and  multi-character  col‐
492       lating  elements used in the expression defined for yesexpr. The locale
493       specified in LC_CTYPE  determines  the  locale  for  interpretation  of
494       sequences of bytes of text data a characters, the behavior of character
495       classes used in the expression defined for the yesexpr. See locale(5).
496

EXIT STATUS

498       The following exit values are returned:
499
500       0     All path operands were traversed successfully.
501
502
503       >0    An error occurred.
504
505

FILES

507       /etc/passwd         Password file
508
509
510       /etc/group          Group file
511
512
513       /etc/dfs/fstypes    File that registers distributed file  system  pack‐
514                           ages
515
516

ATTRIBUTES

518       See attributes(5) for descriptions of the following attributes:
519
520
521
522
523       ┌─────────────────────────────┬─────────────────────────────┐
524       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
525       ├─────────────────────────────┼─────────────────────────────┤
526       │Availability                 │SUNWcsu                      │
527       ├─────────────────────────────┼─────────────────────────────┤
528       │CSI                          │Enabled                      │
529       ├─────────────────────────────┼─────────────────────────────┤
530       │Interface Stability          │Committed                    │
531       ├─────────────────────────────┼─────────────────────────────┤
532       │Standard                     │See standards(5).            │
533       └─────────────────────────────┴─────────────────────────────┘
534

SEE ALSO

536       chmod(1),  cpio(1),  sh(1), test(1), ls(1B), acl(2), stat(2), umask(2),
537       attributes(5), environ(5), fsattr(5),  largefile(5),  locale(5),  stan‐
538       dards(5)
539

WARNINGS

541       The  following options are obsolete and will not be supported in future
542       releases:
543
544       -cpio device     Always true. Writes the current file on device in cpio
545                        format (5120-byte records).
546
547
548       -ncpio device    Always true. Writes the current file on device in cpio
549                        -c format (5120-byte records).
550
551

NOTES

553       When using find to determine files modified within a range of time, use
554       the  -mtime  argument before the -print argument. Otherwise, find gives
555       all files.
556
557
558       Some files that might be under the Solaris root file system  are  actu‐
559       ally  mount  points  for virtual file systems, such as mntfs or namefs.
560       When comparing against a ufs file system, such files are  not  selected
561       if -mount or -xdev is specified in the find expression.
562
563
564       Using  the  -L  or  -follow option is not recommended when descending a
565       file-system hierarchy that is under the control of other users. In par‐
566       ticular, when using -exec, symbolic links can lead the find command out
567       of the hierarchy in which it started. Using -type is not sufficient  to
568       restrict the type of files on which the -exec command operates, because
569       there is an inherent race condition between the type-check performed by
570       the find command and the time the executed command operates on the file
571       argument.
572
573
574
575SunOS 5.11                        15 Aug 2008                          find(1)
Impressum