Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Do you know a good way to find a file or content by name recursively similar to the ms-windows function search with Linux? I can do find . | grep test.html suspecting it's not the best. Thanks for any answer.

For instance, running find . | grep terms.htmlgives my expected result while locate terms.html doesn't even though locate gets updated db - it might have to do with that it's an USB stick the file is on?

share|improve this question

migrated from stackoverflow.com Feb 1 '11 at 19:34

This question came from our site for professional and enthusiast programmers.

8 Answers 8

up vote 13 down vote accepted

The command is find, like this

 find . -iname '*hellofiles*'

you say find ·location· -iname means not case sensitive and in the '' is a regular expression if you wish.

find /home/user -iname '*zip' will find you all the zip files in /home/user

If you want a faster lookup you can use locate, there is a utility which scanns the disc regulary, like every week or day dependin on how it is setup

locate myfile

and it will look in the database if updatedb has seen myfile anywhere.

share|improve this answer
    
This has helped me many times rather than locate –  Niklas rtz Nov 19 '11 at 19:33

In case of packages: dpkg -L packagename

or if you know that it is in a particular folder, add the use of grep, like:

dpkg -L packagename | grep foldername

For example you just installed Chromium and you need to know where is the bin

dpkg -L chromium-browser | grep bin

share|improve this answer

find ./ -name "filename" or you can do something like find ./ -name "*.jar" to find all the files with the .jar extension. You can also do find ./ -name "*.jar" | xargs grep -n 'main' to find all the .jar files that contain a main in them.

share|improve this answer

find . -name test.html or you can use wildcards too: find . -name \*test.html

share|improve this answer

You could use the command find, if you wish to do this via a terminal.

Pipelining find and grep will work, otherwise find provides itself some options (like -name and -iname) to do this:

find DIRECTORY -name test.html
share|improve this answer

There are two utilities find and locate. Since others have suggested find, I will talk about locate.

You install a package named mlocate or slocate on older systems. After installing run the command updatedb. locate uses a database to store the path to all of your files, so searching is much faster but it has the disadvantage of going out of date frequently, and populating the database can take a couple of minutes.

Once you have the database populated just run: locate file. If you just use the name of the file it will search for that file starting from /. So you could get /etc/file and /usr/share/file. If you want to just limit it to your home directory use this:

 locate file | grep /home/user

Wildcards don't work with locate for whatever reason.

share|improve this answer
1  
locate does do shell globs a.k.a. wildcards. You may need to quote your pattern then. You can also use the -r flag to use regular expressions. –  Rich Homolka Feb 1 '11 at 21:07

I don't know the Windows search function, but when you looking for an alternative to | grep * then you can try:

find /* -name "keyword"

slocate should also fit into your criteria.

Regards, /dley

share|improve this answer

find has a number of options that allow it to find files by name, regular expressions or even more complex criteria such as size or ownership. E.g.

find . -iname '*.txt'

See also the example section in the linked manual page.

That said, find has the distinct disadvantage of searching the filesystem each time that you call it. The locate utility, in its many variations, on the other hand, uses a regularly-updated database of the files in your system.

share|improve this answer
    
Thanks! The command find . -iname privacy.html gives the expected result while locate doesn't (it's a file privacy.html I serched after on a USB memory) –  Niklas rtz Sep 1 '11 at 15:45

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.