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.
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)
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
Response to comment:
ls -la "$(locate -d external.db "Duel of Fates (Darth ")"
-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
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
Use "find option Parameter". See "man find" more detail. Use locate to find a document quickly and easily, eg. "locate *.jpg"
- File content
- Modification date
- File emptiness
- Name pattern exclusion
- Name regular expression match
- Hidden and backup files