Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have been using find command to find files on my 1 tb hard disk. it takes very long. then I used locate which proved to be faster with regular update using updatedb. But the limitation of locate is that I cannot find files with certain size or modified/created time. can you suggest me any ideas on how to find files at more speed or in that case how to pipe output of locate command in a way that all other information like size, time, etc. can be displayed or redirected to a file.

share|improve this question
    
Can you please give an example of the full find command including arguments which takes too long? Or find is slow with any arguments for you? On my system find scans the whole filesystem within 2 seconds (100GB). –  arrange Mar 12 '12 at 10:14
    
I replaced the native "search option" with "gnome-do" do.davebsd.com quite some time ago, which lets you search for files of any kind and adds possibilities of quick access and extended sub-functionality, like open, edit, send to mail, open as command etc.. Maybe you find it helpful! –  v2r Mar 12 '12 at 10:23
    
@Chaitanya Is my answer missing something you need? –  hbdgaf Mar 13 '12 at 17:22
    
One of my colleagues suggested me an Idea to use locate database with find to make it work faster which is as follows find $(locate -d external.db 1.txt) That is definitely much faster but it has a problem that it doesnt work on file names with spaces or any special character. Any ideas to refine the command are most welcome –  Chaitanya Mar 19 '12 at 19:05
    
@arrange: I'm not him but find takes several minutes to return on my media and image home server. root@viashivan:/media/data1# find . -type f | wc -l and rhe result is 2044791. –  gecko May 9 '12 at 0:25

6 Answers 6

I haven't seen an answer that comes near the wishes of Chaitanya. If you want to search on filename, a combination of locate, find, ls and grep could be sufficient. But I think Chaitanya want to search for example for 'all files created before 2011'. This can perfectly done with find, but I can imagine it will take a long time searching through 1TB (depends more on the amount of files, not necessarily the total size). To speed this up I think indexing is inevitable. The problem of locate (indexing with updatedb) is that it doesn't index creation time.

So what Chaitanya need is something that indexes the needed attributes of files (file name, file size, creation date, more?). And later something that can search on these attributes. As far as I know there is no out-of-the-box solution for this on Ubuntu.

An important comment of Chaitanya: "Now the thing is that I am designing a php based web gui...". Because your problem sounds quite specific, maybe you want to build somehting yourself. Some suggestions:

  • Index the files in a database (with cronjob) and use SQL to search.

  • Use Lucene to index and search (Zend Lucene for PHP)

share|improve this answer

You can try Tracker. It has a daemon that waits for file changes and updates a database with all the metadata as possible, and a client that you can use to search for files. Note that it only indexes the user dir, not all the hard disk.

The main dawback is that it needs CPU time to index, so use it only if your computer has power to spare.

You will need to install both the server and client, they are named tracker and tracker-gui. If you search for tracker in the Software Center they are the two first matches. If you prefer to install them from the command line:

sudo apt-get install tracker tracker-gui
share|improve this answer
    
Now the thing is that I am designing a php based web gui which will be accessed from a remote machine. so I am limited to use command line tools only. any ideas further are most welcome –  Chaitanya Mar 19 '12 at 19:08

Response to comment:

ls -la "$(locate -d external.db "Duel of Fates (Darth ")"

produces:

-rw-rw-r-- 1 user group 4075134 2012-03-30 22:37 /home/user/Music/Star Wars: Episode 1 - Duel of Fates (Darth Maul's Theme).mp3

Thx @Oli in AskUbuntu chat for tipping me off to "something" to get around shell escapes

share|improve this answer
    
One of my colleagues suggested me an Idea to use locate database with find to make it work faster which is as follows find $(locate -d external.db 1.txt) That is definitely much faster but it has a problem that it doesnt work on file names with spaces or any special character. Any ideas to refine the command are most welcome –  Chaitanya Mar 19 '12 at 19:07

The issue with locate is that it only collects file information occasionally on a regular cron schedule. You if you need mlocate to update its information, just run this

$ sudo /etc/cron.daily/mlocate

If you need a solution that is more "real-time" and updates constantly, I would suggest going with something that is specifically designed to monitor your filesystem, like tracker-gui as Javier Rivera stated.

To redirect the output of locate to a file, just use an arrow > instead of the pipe | character. (One arrow will over write an output file if it already exists. Two arrows will append to an output file if it already exists.)

$ locate filename > output.txt  # Overwrite
$ locate filename >> output.txt # Append
share|improve this answer

Use "find option Parameter". See "man find" more detail. Use locate to find a document quickly and easily, eg. "locate *.jpg"

share|improve this answer
    
One of my colleagues suggested me an Idea to use locate database with find to make it work faster which is as follows find $(locate -d external.db 1.txt) That is definitely much faster but it has a problem that it doesnt work on file names with spaces or any special character. Any ideas to refine the command are most welcome –  Chaitanya Mar 19 '12 at 19:08

Use gnome-search-tool

It provides

  • File content
  • Modification date
  • Size
  • File emptiness
  • Owner/Group
  • Name pattern exclusion
  • Name regular expression match
  • Hidden and backup files
share|improve this answer

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.