Trying to locate a file, how can I search the entire hard drive for a file?

link|improve this question

19% accept rate
Great question. Very useful! – rafalcieslak Dec 28 '11 at 15:55
feedback

5 Answers

up vote 18 down vote accepted

A simple find / -type f -name "" would do the trick if you know exact filename.

find / -type f -iname "filename*" if you want to match more files.

Avoid -type option if you want to search for directories etc. See manual of find for more information. To see the manual, issue the command:

man find

link|improve this answer
Dang, I was just a few seconds slower :P Will edit it to just show the locate command. – nitstorm Dec 21 '11 at 4:47
This will also search all mounted devices as well, might want to just search /mount/hddyouwanttosearch – Callum Rogers Dec 21 '11 at 12:28
Worth noting that find is really slow, compared to an indexed search system, such as locate (but also more powerful) – tumbleweed Dec 23 '11 at 6:30
feedback

You could also use locate to look for commands. Why do people use locate if find does the job? Because locate is much more faster than find since it just searches through a database(s) of indexed locations to find your file/regex.

Example:

locate some-file.avi searches through a database(s) that is maintained of almost every file on the disk, for a file called "some-file.avi"

locate -i "some-file.avi" will ignore the case of the file you are searching for.

locate -i "*.txt" will display a list of location of all the files with *.txt extension on your system.

man locate for more info on the file..

You might need to run updatedb first to ensure the index database is up to date, otherwise, 'locate' might not return what you are looking for.

link|improve this answer
Note that updatedb must be run as root. – rafalcieslak Dec 28 '11 at 15:56
feedback

If you're looking for a string inside a file, you can use grep. Here's a sample command:

grep -r -i "some string" /home/yourusername

This will find "some string" in /home/yourusername directory. The search will ignore case (-i) and recurse directories (-r). You can use / as the directory to search in the whole directory but that might not be very efficient.

link|improve this answer
feedback

On Ubuntu, i know that everyone wants to be dogmatic about using command line all the time, and I have in the past been that way, but I love the Gnome "Search for files..." tool. I think its awesome.

link|improve this answer
well i'm on a server – Blankman Dec 21 '11 at 4:50
You should try then the KDE search. It is far better than the gnome one. I am still waiting for Nautilus to catch up with the versatility that the KDE search system has. Dolphin/Konqueror are far better because of it. – Luis Alvarado Dec 21 '11 at 4:53
Yeah, I was thinking about switching to Kubuntu actually. I'll take a look at it. – djangofan Dec 22 '11 at 1:04
feedback

Start by clicking the "Home Folder" icon in the launcher.

enter image description here

In the window that opens, click "Search".

enter image description here

Type what you want to search for in the box, then press enter. enter image description here

Under the dropdown for location, choose your hard drive, then click reload.

enter image description here

The results will then be displayed. Hope that helps!

link|improve this answer
1  
The man who asked it states he uses a server, so there is no GUI. But that's a great answer anyway! – rafalcieslak Dec 28 '11 at 15:57
feedback

Your Answer

 
or
required, but never shown

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