Operating System - HP-UX
1753963 Members
7621 Online
108811 Solutions
New Discussion юеВ

How do I search for a particular file?

 
SOLVED
Go to solution
Joshua Goi
Frequent Advisor

How do I search for a particular file?

Hi,

How do I search for a particular file using the find command? Say I want to find every file that ends with bsm (*bsm). How do I do that?
9 REPLIES 9
Jeff_Traigle
Honored Contributor

Re: How do I search for a particular file?

find / -name *bsm

Assuming you want to start frm the root directory.
--
Jeff Traigle
A. Clay Stephenson
Acclaimed Contributor

Re: How do I search for a particular file?

find . -name '*bsm'
If it ain't broke, I can fix that.
Sanjay_6
Honored Contributor

Re: How do I search for a particular file?

Hi,

use,

find / -name *bsm -print

Hope this helps.

Regds
Geoff Wild
Honored Contributor

Re: How do I search for a particular file?

As others have said:

find / -name *bsm -print

man find
will give you some good examples.

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: How do I search for a particular file?

Actually, it is very important that you enclose thwe wildcard pattern in quotes (e.g. -name '*bsm') so that the find command rather than the shell expands the argument. -name expects exactly one argument. If you have multiple files that end with bsm in the current directorty, -name *bsm will see multiple arguments and lead a find parse failure but -name '*bsm' will supply exactly one argument. The -print is implicit but you can supply it, if you like. All that is really necessary (starting from the current directory, . ) is find . -name '*bsm'
If it ain't broke, I can fix that.
Kent Ostby
Honored Contributor

Re: How do I search for a particular file?

If you want to find them also do an ll on them, you would do:

find . -name '*bsm' -exec ll {} \;

Best regards,

Kent M. Ostby
"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
SANTOSH S. MHASKAR
Trusted Contributor

Re: How do I search for a particular file?

$ find / -name "*bsm"

-Santosh
Jeroen Peereboom
Honored Contributor

Re: How do I search for a particular file?

In addition to the other replies:
- Quotes are indeed essential ('*bsm' or '*.bsm').
- Since find is not really a fast command you may want to schedule a daily / weekly cron job to 'find' all local files for you (not the cd, not nfs) and put this list in a file 'allfiles'. Next time you want a file you just do a grep '*.bsm' allfiles.

JP.
Joshua Goi
Frequent Advisor

Re: How do I search for a particular file?

Thanks people for the help.