FIND
Section: User Commands (1)
Updated: 20 June 1986
Index
Return to Main Contents
NAME
find - find files
SYNOPSIS
find
pathname-list expression
DESCRIPTION
find recursively descends the directory hierarchy for each
pathname in the pathname-list, seeking files that match a boolean
(logical) expression written in the primaries given below.
In the descriptions, the argument n
is used as a decimal integer where +n means more than n,
-n means less than n, and n means exactly
n.
- -fstype type
-
True if the filesystem to which the
the file belongs is of type type, where type is
typically
4.3
or
nfs.
- -name filename
-
True if the filename argument matches the current file name.
Shell argument syntax can be used if escaped (watch out for
[,
? and
*).
- -perm onum
-
True if the file permission flags exactly match the octal number onum
(see
chmod(1V)).
If onum is prefixed by a minus sign, more flag bits (017777, see
stat(2))
become significant and the flags are compared:
(flags&onum)==onum.
- -prune
-
Always yields true. Has the side effect of pruning the search
tree at the file. That is, if the current path name is a directory,
find will not descend into that directory.
- -type c
-
True if the type of the file is c, where c is one of:
-
- b
-
for block special file,
- c
-
for character special file,
- d
-
for directory,
- f
-
for plain file,
- p
-
for named pipe (FIFO),
- l
-
for symbolic link, or
- s
-
for socket.
- -links n
-
True if the file has n links.
- -user uname
-
True if the file belongs to the user uname.
If uname is numeric and does not appear as a login name in the
passwd(5)
database, it is taken as a user ID.
- -nouser
-
True if the file belongs to a user
not
in the
passwd
database.
- -group gname
-
True if the file belongs to group gname.
If gname is numeric and does not appear as a login name in the
group(5)
database, it is taken as a group ID.
- -nogroup
-
True if the file belongs to a group
not
in the
group
database.
- -size n
-
True if the file is n blocks long (512 bytes per block).
If
n
is followed by a
c,
the size is in characters.
- -inum n
-
True if the file has inode number n.
- -atime n
-
True if the file has been accessed in n days.
Note that the access time of directories in
path-name-list
is changed by
find
itself.
- -mtime n
-
True if the file has been modified in n days.
- -ctime n
-
True if the file has been changed in n days.
``Changed'' means either that the file has been modified or some attribute
of the file (its owner, its group, the number of links to it, etc.) has been
changed.
- -exec command
-
True if the executed command returns a zero value as exit status.
The end of command must be punctuated by an escaped semicolon.
A command argument {} is replaced by the current pathname.
- -ok command
-
Like
-exec
except that the generated command is written on
the standard output, then the standard input is read
and the command executed only upon response
y.
- -print
-
Always true; the current pathname is printed.
- -ls
-
Always true;
causes current pathname to be printed together
with its associated statistics.
These include (respectively) inode number,
size in kilobytes (1024 bytes),
protection mode,
number of hard links,
user,
group,
size in bytes,
and modification time.
If the file is a special file
the size field will instead contain the major and minor
device numbers.
If the file is a symbolic link the
pathname of the linked-to file is printed preceded by ``->''.
The format is identical to that of ``ls -gilds''
(note however that formatting is done internally,
without executing the ls program).
- -cpio device
-
Always true;
write the current file on
device
in
cpio
format (5120-byte records).
- -ncpio device
-
Always true;
write the current file on
device
in
cpio-c
format (5120-byte records).
- -newer file
-
True if the current file has been modified more recently than the
argument file.
- -xdev
-
Always true;
causes find
not
to traverse down into a file system different
from the one on which current
argument
pathname resides.
- -depth
-
Always true;
causes descent of the directory hierarchy to be done
so that all entries in a directory are
acted on
before the directory itself.
- ( expression )
-
True if the parenthesized expression is true
(parentheses are special to the shell and must be escaped).
- !primary
-
True if the primary is false (`!' is the unary not operator).
- primary1 [ -a ] primary2
-
True if both primary1 and primary2 are true.
The
-a
is not required. It is implied by the juxtaposition of two
primaries.
- primary1 -o primary2
-
True if either primary1 or primary2 is true
(`-o' is the
or operator).
EXAMPLE
In our local development system, we keep a file called TIMESTAMP in
all the manual page directories. Here is how to find all entries that have
been updated since TIMESTAMP was created:
-
angel% find /usr/man/man2 -newer /usr/man/man2/TIMESTAMP -print
/usr/man/man2
/usr/man/man2/socket.2
angel%
To find all the files called intro.ms starting from the current
directory:
-
angel% find . -name intro.ms -print
./manuals/assembler/intro.ms
./manuals/sun.core/intro.ms
./manuals/driver.tut/intro.ms
./manuals/sys.manager/uucp.impl/intro.mss
./supplements/general.works/unix.introduction/intro.mss
./supplements/programming.tools/sccs/intro.mss
angel%
To recursively print all files names in the current directory and below,
but skipping SCCS directories:
-
angel% find . -name SCCS -prune -o -print
angel%
To recursively print all files names in the current directory and below,
skipping the contents of SCCS directories, but printing out the
SCCS directory name:
-
angel% find . -print -name SCCS -prune
angel%
To remove files beneath your home directory named `a.out' or `*.o'
that have not been accessed for a week
and that aren't mounted using NFS:
-
angel% cd
angel% find . \( -name a.out -o -name '*.o' \) -atime +7 -exec rm {} \; -o -fstype nfs -prune
FILES
/etc/passwd - if NetInfo is not running
/etc/group - if NetInfo is not running
SEE ALSO
chmod(1V), sh(1), test(1V), fs(5), netinfo(5)
Index
- NAME
-
- SYNOPSIS
-
- DESCRIPTION
-
- EXAMPLE
-
- FILES
-
- SEE ALSO
-
This document was created by
man2html,
using the manual pages.
Time: 01:00:18 GMT, September 26, 2024