-   Linux - Newbie (
-   -   ls -R {filename} How do I search for a single file? (

Coldmiser 04-30-2004 04:39 PM

ls -R {filename} How do I search for a single file?
Somethings I can do on Linux and still some simple stuff illudes me.
I can write a perl program, have it create an entry into a MySQL database and then have the same perl file e-mail a confirmation back to the user, but I still cannot find a simple file on the server.

In Perl I am told that I need to edit my file with the smtp server or I am going to have to put my smtp server entry in every file. I would rather just edit my file.

Only problem is, I can't find the darn thing. I've tried 'ls -R' but apparently that is not the correct way to use ls

MY REAL PROBLEM (enough venting now) : If someone could just PLEASE answer a simple question of how to do a recursive file find. Something similar to a dos 'dir/s filename.txt'

Thank you in advance for answering probably the stupidest question of the day. I already feel like a DOLT for having to resort to asking. :cry:

david_ross 04-30-2004 04:40 PM

If you have slocate installed:

find / -name

SciYro 04-30-2004 06:31 PM

maybe use grep with ls also?

J.W. 04-30-2004 11:38 PM

I suppose if you want to use grep you could, but david_ross' answer solves the problem. To expand on his answer to make it a little more generic, you could run either:

slocate <search-string>


find <path> -name <search-string>

where <search-string> is what you're interested in finding and <path> is the directory from which you want to start searching. (Note that you shouldn't use wildcards in the search-string with slocate, but that you could/should use wildcards with find. Personally I think slocate is the way to go, assuming you've got it.) Lastly, if you use "find" as a regular user and you start searching from the top root directory, you are likely to get a lot of permission errors as a result of attempting to access directories that are off-limits. -- J.W.

SciYro 05-01-2004 06:18 AM

i never did like slocate, it requires to keep a database of my files, and i see that as a security risk (ok, more like I'm a lazy kid that don't want a stupid database of files because the FS is the database of files ..... and also i don't like running meaningless processes, find and ls work *slower no doubt* and better in my opinion)

|2ainman 05-01-2004 08:45 AM

find <path> -name <pattern> -print 2>/dev/null
much better :)

grcunningham 05-01-2004 10:06 AM

if you decide to use slocate (in RedHat you can just use
locate), make sure you have run updatedb first

All times are GMT -5. The time now is 08:48 PM.