Friday, March 7, 2008

Using Unix Find Command

Find:
find . -name "wfstatus.sql" -print
the above command will search all directories starting from current directory for any file containing wfstatus.sql.
Problem: find displays an error message for any directory I do not have permissions.
So how do I suppress these messages?
The following command will do the trick:

find . - name "wfstatus.sql " -print 2> /dev/null
will suppress cannot read dir or Permission denied messages and print only if it finds the file.
Output of this command:
/oracle/prodappl/fnd/11.5.0/sql/wfstatus.sql

explanation:
/dev/null is a virtual file in Unix; data written to is deleted.
I use the cheatsheet from Stanford.edu (to go to stanford clickhere )

In order to do a case-insensitive search, instead of "name", use "iname":
find . -iname "WFSTAtus.sql" -print 2>/dev/null

if you want the search to be restricted only to files, then use "-type f"
find . -type f -iname "WFSTAtus.sql"   -print 2>/dev/null
I have posted a list of commands that I use frequently in Linux. List of Commands I use frequently in Linux