start page | rating of books | rating of authors | reviews | copyrights

Unix Power ToolsUnix Power ToolsSearch this book

9.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 9-1. Note, though that some versions of find don't have all of these.

Table 9-1. find -type characters

Character

Meaning

c

Block special file ("device file")

c

Character special file ("device file")

d

Directory

f

Plain file

l

Symbolic link

p

Named pipe file

s

Socket

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, here is another way to list files recursively:

% 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 to which your symbolic links point. $NF gives the last field of each line, which holds the name to which a symlink points. If your find doesn't have a -ls operator, pipe to xargs ls -l as previously.

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

-- BB



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.