Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Absoulte beginner usage of 'find'

Status
Not open for further replies.

Taxidriver

Programmer
Jan 15, 2002
79
IT
I can't manage to find a file using the command 'find'. Can you help me with the corrent syntax?
 
find / -name file1* -print

This will find any instances of files named that begin with 'file1' or are in any subdirectories named 'file1'

find / -name '*.txt' -print

This will do the same, but seach for the file extension txt

If you want to search within a specific directory then you can use something like:

find /etc -name ....

Common tags used with the find command include -size and
-atime, to specify the file size limit and time of last access. For example:

find / -name file1* -size -50k -atime -7

This will do the same as the first example mentioned, but will limit size to 50k or less and time of creation to 7 days or less.

I am not on a Linux box at the moment and these are off the top of my head, so I cannot test them.

Post back if you are still having trouble.
 
Ok, I managed to do that without -print.
I am using Debian, what caused me trouble was that I got long lists of paths instead of getting the desired path only. Thanks.
 
If the desired path is only the / directory, no need to use find, use ls instead...

ls -1 /filename*
lists the file(s) in single column in the / directory.

ls -l /filename*
long listing of file(s).


man ls
HTH
 

Well, I am old school system V, but, I have always gotten myself to where I want to search from recursively and typed:

find . -depth -name filenamehere -print

You can wildcard a name, though that will naturally give you a lot more hits.

Try that and see what it gives you, because if I recall it should only spit out the paths that have results matching your find.

Good luck!

 
If you use wildcards with [tt]find[/tt], it is usually a good habit
to always put the "name" in quotes...

For instance:
[tt] % cd /usr/local/lib[/tt]

This will fail:
[tt] % find -name *.so [/tt]

But this is OK:
[tt] % find -name "*.so" [/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top