home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 17.3 Don't Forget -print Chapter 17
Finding Files with find
Next: 17.5 Searching for Old Files
 

17.4 Looking for Files with Particular Names

You can look for particular files by using a regular expression with metacharacters ( shell wildcards, not grep -like expressions ( 26.2 ) ) as an argument to the -name operator. Because the shell also understands these metacharacters, it is necessary to quote ( 8.14 ) them so they are passed to find unchanged. Any kind of quoting can be used:

% 

find . -name \*.o -print


% 

find . -name '*.o' -print


% 

find . -name "[a-zA-Z]*.o" -print

Any directory along the path to the file is not matched with the -name operator, merely the name at the end of the path. For example, the commands above would not match the pathname ./subdir.o/afile -but they would match ./subdir.o and ./src/subdir/prog.o .

csh_init
sh_init
Article 17.24 shows a way to match directories in the middle of a path. [Here's a "find file" alias:

alias ff "find . -name '*\!{*}*' -ls"

Give it a file or directory name; the alias will give a long listing of any file or directory names that contain the argument. For example:

% 

ff makedirs


415863  3 -rw-r--r--  1 359   daemon    2072 Feb 19  1994 ./adir/makedirs.sh

Very handy. -JP  ]

- BB


Previous: 17.3 Don't Forget -print UNIX Power Tools Next: 17.5 Searching for Old Files
17.3 Don't Forget -print Book Index 17.5 Searching for Old Files

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System