LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to search all directories for a file in bash (http://www.linuxquestions.org/questions/linux-newbie-8/how-to-search-all-directories-for-a-file-in-bash-544407/)

overlook1977 04-08-2007 08:54 PM

How to search all directories for a file in bash
 
I know I can search with the KDE search function, but how would I search for a file if I did not know what directory it was located in? I was looking for 'xorg.conf'. I went into bash and typed 'whereis xorg.conf' but it returned "xorg". The file turned out to be in 'etc/X11'. I guess a bash command that would open the lost file would work, but is there a way to get bash to tell you the full path?

cgjones 04-08-2007 08:57 PM

Code:

find / -type f -iname xorg.conf
You might want to do this as root, otherwise you'll get a bunch of "Permission denied" errors.

SlowCoder 04-08-2007 09:28 PM

For your instance, try 'locate xorg.conf'.

overlook1977 04-08-2007 09:29 PM

thanks! is there a way to force the shell to stop searching? this would be done by using ctrl-break in Windows, is there an equivalent?

cgjones 04-08-2007 09:33 PM

Ctrl-c should terminate the search.

SlowCoder 04-09-2007 09:35 AM

The locate command uses a database catalog that is rebuilt nightly. Unless your files are newer than a day or so, you should be able to use locate. It is much faster than the find command. Find is great for finding files that have been newly added.

MoMule 04-09-2007 12:15 PM

type:

updatebd
# followed by
locate <file being searched>

The updatedb command will update the database immediately.

Deion "Mule" Christopher

bandwidthjunkie 04-10-2007 07:00 AM

I would have thought that with slackware you would need to add
Code:


updatedb

to the daily cron run (the script needs root permissions) http://www.unixgeeks.org/security/ne...ix/cron-1.html. Then you can run
Code:


slocate blah

to find all instances of blah on your box. I find a useful search if I am looking for a program is
Code:


slocate blah | grep bin

This weeds out all the other rubbish and gives me what I'm looking for.


All times are GMT -5. The time now is 02:34 AM.