« How business works: part 95 | Main | Shafted again: Telecom fight back »


The Linux find command is enormously powerful but, like many command-line tools, you need to be a syntactical wizz-kind to work with all its parameters. (I have a sneaking suspicion I could use it to locate Lord Lucan and the wreck of the General Grant if only I could master its syntax!)

There are GUI versions -- check out the gnome-search-tool in Gnome and kfind in KDE -- but most of the time you just want a snappy response to a simple question. Like just now, for instance. I was tinkering with my Konqueror configuration and wanted to find all instances of the konqueror.rc file. Piece of cake. I just went to a console, typed locate konqueror.rc and almost instantly the two locations were listed.

locate is the business end of the updatedb command, which most distros run automatically behind the scenes each day. (Or you can run it yourself as root.) updatedb stores file names in a database which locate then searches -- and that's much quicker than scanning the disk.

Of course, being a command-line tool means you can use wildcards and add other commands to it too. So locate *.png | grep tux will find all .png files then filter the result to only display those containing "tux".

That's pretty simple. But of course with a little practice, you could soon start to build up some really complex syntax...




<--Previous Hidden Linux        Next Hidden Linux -->



Comments

locate, one of the best commands inside linux.

Be aware of using characters that have special meaning in the shells:

locate *.png | grep tux

may replace *.png with all png files in current directory. You really don not need the *, just write:

locate .png | grep tux

or better

locate .png | grep -i 'tux.*png$'

Hi -
I have a couple of other search apps which are even better than "find" (the reason being that with both of these, they are automatic - no updating at all is needed from the user).

First, there is "Tracker" -
http://www.gnome.org/projects/tracker/

If you use a Debian-based distro, "apt-get install tracker" will install that for you. I use Linux Mint 4.0 - if you grab that, it has Tracker included.
You won't regret trying it!

Then there is the excellent (if uninspiringly-named)
Deskbar -
http://raphael.slinckx.net/deskbar/
If you are running a Gnome desktop, right-click on the "panel" (the bar at the bottom of the screen). You'll see an option "Add to panel" - choose that, and you'll see a number of possible applets to add. Deskbar should be one of them. Add it, then just click on its icon in the panel to use it. Highly recommended!

Finally, there is Catfish. Not a search tool in itself, but a graphical front-end for several of them (including Tracker)-
http://software.twotoasts.de/?page=catfish

- Andy

Since this seems to be written to those less familiar with the commandline, perhaps mentioning using a case-insensitive search would be beneficial, as they may have titled their file "SuperTux.png" or such.

In that case, the syntax of your command would be better represented as:
locate -i *.png | grep -i tux

Yeeees!
I didn't know this command, that's exactly what I've been searching for AGES!
Tahnks!
Jo

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

Subscribe
Newsletter & SubscriptionsPC World is New Zealand’s top selling computing and technology magazine.

It provides up-to-the-minute editorial, insight and buying advice for personal computing, cell phones, game consoles, digital entertainment and broadband.
SIGN UP
PCWorldUpdate
PC World's weekly round-up of tech news, gear and game reviews, software selections, and handy How Tos.