17.23 Finding Files with -prunefind has lots of operators for finding some particular kinds of files. But find won't stop at your current directory - if there are subdirectories, it looks there too. How can you tell it "only the current directory"? Use -prune .
-prune prunes find 's search tree at the current pathname. So, if the current pathname is a directory, find won't descend into that directory for any further searches. The command line looks kind of hairy. Here's one to find all files from the current directory modified in the last 24 hours: % I'll put that into an alias in a minute. First let's try to understand it - once you see the pattern, you'll understand some important things (8.5 , 17.12 ) about find that many people don't. Let's follow find as it looks at a few pathnames. find
looks at each entry, one by one, in the current directory
(
Your find
may also have a -maxdepth
option that gives the
maximum number of directory levels to descend.
For example, Let's put the version with -prune into a couple of aliases. The first one, named find. (with a dot on the end of its name), just prints names with -print . The second alias gives a listing like ls -gilds . They work like this: % The find. alias is handy inside backquotes (9.16 ) , feeding a pipe, and other places you need a list of filenames. Here are the aliases. The second one, find.ls , uses -ls instead of -print : alias find. 'find . \( -type d ! -name . -prune \) -o \( \!* -print \)' alias find.ls 'find . \( -type d ! -name . -prune \) -o \( \!* -ls \)' (The Bourne shell versions on the CD-ROM are named Find and Findls because a dot isn't legal in a function name.) If you don't want the - |
|