Monday, September 19, 2011

Finding Files and Directories

Sometimes you want to locate a file, but you aren’t sure where it might be located in the file system.
The whereis command, of course, is of help only if you are locating commands, not files. To find out
where a file or a directory is, you can use the find command, as shown here:

$ pwd
/u01/app/oracle

$ find . -name bilal.sql -print
./dba/bilal.sql
$
In this example, the find command informs you that the bilal.sql file is located in the /u01/app/
oracle/dba directory. Note that there is a dot after the find keyword, indicating that a recursive
search is made from the present directory—every directory and subdirectory under the present
directory will be searched. If you want to search from a specific directory, you need to specify that in
the command. In the following example, the find command starts its search from the root (/) file
system and prints the location of the test.txt file to the screen, if it finds it:
$ find / -name test.txt -print