next up previous contents
Next: Archiving Directories Up: Basic Directory Commands Previous: Directory Removal

Searching Directories

The find command can be used to locate files within in a directory tree. Searching for a file by name is done in the following way:

find <directoryname> -name <filename> -print

This will cause a search for the filename starting at the directory given. After searching the parent directory, find will recursively descend into any subdirectories of that directory. The -print option tells find to print the absolute path to all of the occurrences of the filename in the directory tree. As an example, to search the current directory and all subdirectories for a file named ''core'' you would issue the following command:

find -name core -print

If the file is not found, then find returns to the command prompt without doing anything. Use the -ls option to list file attributes and sizes of the files that find found. The find command can be used to find files of a specific type, with specific attributes, or a combination of attributes.

The find command can also be used to remove files matching a pattern, or to execute a specific command using the found files as input -exec option .

See man find for more details and options to the find command.


next up previous contents
Next: Archiving Directories Up: Basic Directory Commands Previous: Directory Removal
World Wide Web Administrator
1/5/1999