Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ find(1) — SunOS 4.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

cpio(1)

sh(1)

ln(1)

chmod(1V)

ls(1V)

test(1V)

cpio(5)

fs(5)

FIND(1)  —  USER COMMANDS

NAME

find − find files by name, or by other characteristics

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 using the operators listed below. 

find does not follow symbolic links to other files or directories; it applies the selection criteria to the symbolic link itself, as if it were an ordinary file (see ln(1) for a description of symbolic links). 

USAGE

Operators

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.2 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 chmod(1V)) become significant and the flags are compared: (flags&onum)==onum.

−pruneAlways 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 cTrue if the type of the file is c, where c is one of:

b for block special file c

cfor character special file

dfor directory

ffor plain file

pfor named pipe (FIFO)

lfor symbolic link

sfor socket

−links nTrue 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 /etc/passwd database, it is taken as a user ID. 

−nouserTrue if the file belongs to a user not in the /etc/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 /etc/group database, it is taken as a group ID. 

−nogroupTrue if the file belongs to a group not in the /etc/group database. 

−size nTrue if the file is n blocks long (512 bytes per block).  If n is followed by a c, the size is in characters. 

−inum nTrue if the file has inode number n.

−atime nTrue if the file has been accessed in n days.  Note: the access time of directories in path-name-list is changed by find itself. 

−mtime nTrue if the file has been modified in n days. 

−ctime nTrue 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. 

−printAlways true; the current pathname is printed. 

−lsAlways true; prints current pathname 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’ ( See ls(1V)).  Note: formatting is done internally, without executing the ls program. 

−cpio deviceAlways true; write the current file on device in cpio(5) format (5120-byte records). 

−ncpio device
Always true; write the current file on device in ‘cpio−c’ format (5120-byte records). 

−newer fileTrue if the current file has been modified more recently than the argument filename.

−xdevAlways true; find does not to traverse down into a file system different from the one on which current argument pathname resides. 

−depthAlways true; performs descent of the directory hierarchy so that all entries in a directory are acted on before the directory itself.  This can be useful when find is used with cpio(1) to transfer files that are contained in directories without write permission. 

( expression )
True if the parenthesized expression is true (parentheses are special to the shell and must be escaped). 

!primaryTrue 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:

example% find /usr/share/man/man2 −newer /usr/share/man/man2/TIMESTAMP −print
/usr/share/man/man2
/usr/share/man/man2/socket.2
/usr/share/man/man2/mmap.2
example%

To find all the files called intro.ms starting from the current directory:

example% 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
example%

To recursively print all files names in the current directory and below, but skipping SCCS directories:

example% find . −name SCCS −prune −o −print
example%

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:

example% find . −print −name SCCS −prune
example%

To remove files beneath your home directory named a.out or ∗.o that have not been accessed for a week and that are not mounted using NFS:

example% cd
example% find . \( −name a.out −o −name ’∗.o’ \) −atime +7 −exec rm {} \; −o -fstype nfs −prune

FILES

/etc/passwd

/etc/group

a.out

∗.o

SEE ALSO

cpio(1), sh(1), ln(1), chmod(1V), ls(1V) test(1V), cpio(5), fs(5)

Sun Release 4.0  —  Last change: 9 September 1987

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026