Documented in Volume 1 of the UNIX Programmers Manual.
% find . -name myprog -print
search for the filename 'myprog' by descending
from the present directory (.) recursively.
Each time a filename of `myprog' is found, display it.
% find / \( -name csh -o -name sh \) -print
descend from the root directory (/) recursively
looking for and displaying files named 'csh' or sh'.
% find / \( -name a.out -o -name '*.o' \) -atime +7 -exec rm {} \;
remove all files named `a.out' or `*.o' that have not
been accessed for a week.
From: dave@lsuc.UUCP (David Sherman)
{allegra decvax ihnp4 linus}!utcsrgv!lsuc!dave
Re: How can I find where a link leads to ???
Well, strictly speaking, a link leads to its inode, which you can
find with "ls -i". But I suspect you want to know what other links
there are to the same inode.
If you have access to the raw disk (you usually have to be root),
type "ncheck -i 1234 /dev/abc", where 1234 is the inode you want
and /dev/abc is the disk device (the raw device, /dev/rabc, will
be faster, actually).
In other cases, you need to start at the root of the file system in
question and search for the inode you want. One way is:
% find /abc -inum 1234 -print
If you can, start this search further down the tree (e.g., if you're
pretty sure the link is somewhere in your own files, start it at
your home directory).
Another way is,
% ls -R1i /abc | grep 1234
but this will only give you the file names, not their directories.
(If you examine the entire ls output by hand, you'll see the directories.)
From: rpw3@redwood.UUCP (Rob Warnock)
Subject: Re: creating pipes in find(1)
Problem:
How do I build a pipe within the exec portion of find? Example:
% find /etc -name printcap -exec cat {} | lpr \;
I've tried lots of combinations of escaped parens, exec'ing
the shell, etc and nothing works...
I have never gotten it to work either (except like your "junk" auxiliary
shell script), but the following neat/ugly/cute/hacky method sprang to mind
one day as I was reading Kernighan & Pike [pp 86-87ff, see also "pick"]:
$ for i in `find . -print`
>do echo $i # so we can see what we're doing
>cat -v $i | lpr # ...or anything you want at all...
>one
For C-shell users, that's:
% foreach i (`find . -print`)
? echo $i # so we can see what we're doing
? cat -v $i | lpr
? end
This lets you do more than one thing to the file, as well. Normally, the
"{}" token can be used exactly once, so things like "mv {} {}-" don't work.
Here, you can play games like "mv $i olddir/`basename $i`.old", and such.
K & P also show an example of using "grep" to select files by their
contents....
WARNING: Make sure that the "find" is not going to give you so much stuff
that your shell (or your system) blows up from an over-large argument list.
(That is, DON'T do "for i in `find / -print`")