Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to locate all copies of example.filename on my FreeBSD server. What's the best / easiest / most efficient way to do this?

share|improve this question
1  
While the answers will be similar, you might want to clarify whether you are using Linux, or FreeBSD. They aren't the same thing. –  Greg Hewgill Apr 30 '09 at 23:17
    
edited title to make the OS more specific –  Ian Apr 30 '09 at 23:22
    
This should probably be tagged FreeBSD, but I lack the reputation to do so. –  mikl May 5 '09 at 8:33

6 Answers 6

up vote 12 down vote accepted
find / -name example.filename
share|improve this answer
2  
Reliable, but slow. Sometimes very slow. –  dmckee Apr 30 '09 at 23:15
3  
other 'find' flags that may be appropriate, depending on the need: -type f (won't bother with directories or symlinks with the same name) -ls (to show details such as size of the file, e.g. if files have same name but different contents) –  Zac Thompson May 4 '09 at 4:13
locate filename

Much faster than find, if you're running the locate service, and it only finds files that existed at the time updatedb last ran (usualy the night befor under the control of a cron job).

You can run updatedb by hand, but that is even slower than the find cletus suggests, and requires root. I sometimes update the database by hand after installing a bunch of new stuff.

share|improve this answer
3  
Locate only works if you have the service running to build the locate db (forget what it's called). It can also suffer from time delay (in that the file you're looking for may have been added since the last build). –  cletus Apr 30 '09 at 23:15
    
Edits and comments crossed on the wire. Cool. You are, of course, right on both counts. –  dmckee Apr 30 '09 at 23:16
4  
If you find yourself doing find / or on any large tree more than once a week, then running the locate service is probably worthwhile, because locate(1) is so much faster. –  Drew Stephens May 1 '09 at 0:38

If you've got locate (aka slocate) installed, then

locate example.filename

locate runs a cron job every night that reindexes all the files on your machine. It's not always up to date for that reason.

share|improve this answer

Sometimes you want to find files at a specific directory level. In this case it can be convenient to use shell wildcards:

ls /data/*/example.filename

Obviously this only works if you have a rigid directory structure.

share|improve this answer

If you have the locate database up-to-date, then just:

locate example.filename
share|improve this answer

I sometimes do


  find . | grep example.filename

probably hugely inefficient however.

share|improve this answer
    
Yup, that matches everything then throws away everything except for that one name you were looking for. Instead you can simply do ' find -name "example.filename" ' which does exactly the same stuff without first printing everything and without running an extra grep process. –  Mihai Limbăşan May 2 '09 at 19:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.