UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 17.12 Finding Many Things with One Command Chapter 17
Finding Files with find
Next: 17.14 Searching for Files by Size
 

17.13 Searching for Files by Type

If you are only interested in files of a certain type, use the -type argument, followed by one of the characters in Table 17.1 [some versions of find don't have all of these -JP ].

Table 17.1: find -type Characters
CharacterMeaning
bBlock special file ("device file")
cCharacter special file ("device file")
dDirectory
fPlain file
lSymbolic link
pNamed pipe file
sSocket

Unless you are a system administrator, the important types are directories, plain files, or symbolic links (i.e., types d, f, or l).

Using the -type operator, another way to list files recursively is:

xargs 
 % find . -type f -print | xargs ls -l

It can be difficult to keep track of all the symbolic links in a directory. The next command will find all the symbolic links in your home directory and print the files that your symbolic links point to. [$NF gives the last field of each line, which holds the name a symlink points to. -JP] If your find doesn't have a -ls operator, pipe to xargs ls -l as above.

% find $HOME -type l -ls | awk '{print $NF}'

- BB


Previous: 17.12 Finding Many Things with One Command UNIX Power ToolsNext: 17.14 Searching for Files by Size
17.12 Finding Many Things with One Command Book Index17.14 Searching for Files by Size

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