14

I often use "locate" command on CentOs to find files.

What's the alternative for this command on Debian ?

terdon
  • 234,489
  • 66
  • 447
  • 667
chubbyk
  • 275
  • 1
  • 2
  • 5

5 Answers5

31

I recommend locate.

sudo apt-get install locate
mikeserv
  • 57,448
  • 9
  • 113
  • 229
  • 12
    You may have to `sudo updatedb` to build an index. – wchargin Jun 15 '14 at 18:19
  • In my case, `locate` did provide the command, but the package `mlocate` gave me some configuration files such as `/etc/updatedb.conf` that allowed for smoother use. – xryophile Oct 10 '20 at 17:01
12

locate
As the word itself suggests to locate files maybe you can install locate command, from the original GNU findutils (code here), or from the new implementation Debian buster (on the right side the link to the sources).

whereis
To locate only the binary, source, and manual page files for a command you can always use whereis, remembering that whereis has a hard-coded path, so it may not always find what you're looking for (if not included in that hard-coded path).

The whereis command is part of the util-linux package and is available from https://www.kernel.org/pub/linux/utils/util-linux/

which
which instead locates a command and returns the pathnames of the files (or links) which would be executed in the current environment, by searching the $PATH for executable files matching the names of the arguments.
If used with -a option it will print all matching pathnames of each argument.

find
Less efficient in terms of time, more slow because there isn't a database, it can result more efficient in terms of solutions proposed. Locate needs that the database is updated, (run updatedb frequently), if not you will have a partial or wrong result. Moreover, it is possible that some extensions or directories are excluded from the database (see /etc/updatedb.conf file).

Desktop solutions
If you are searching only for a program indexed with a database, you can see projects for desktop such as Nepomuk, Strigi, Soprano KDE, Virtuoso and Akonadi, but even Deskbar-applet, Beegle for Gnome. They are somehow similar to the discontinued Google Desktop.
Some of the database systems can be used from command line too.

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Hastur
  • 2,325
  • 16
  • 32
  • If interested, it is possible to find some additional words [About Strigi, Soprano, Virtuoso et cetera](https://trueg.wordpress.com/2011/09/22/about-strigi-soprano-virtuoso-clucene-and-libstreamanalyzer/) and some of their differences, probably not completely on-topic here. – Hastur Mar 05 '20 at 15:33
7

You can have locate on Debian as well—you may just need to install it. There are (at least) two implementations available, in the locate and mlocate packages.

Installing either one will give you a locate command.

The mlocate version has some additional features (hiding names based on permissions, faster indexing).

derobert
  • 107,579
  • 20
  • 231
  • 279
  • [pagure.io/mlocate](https://pagure.io/mlocate) is the new official home site of mlocate. – Pablo A Jul 08 '17 at 03:59
  • @PabloBianchi *(confused)* I'm not sure what that has to do with this answer—any Debian user is going to `apt install mlocate` (or similar) to install it. Could you please elaborate how you're suggesting I improve the answer (or maybe just suggest an edit?). On the off-chance you're reporting the outdated location at https://tracker.debian.org/pkg/mlocate and in the package, that should be sent to Debian as a bug report. I've just done so, see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=867640 – derobert Jul 08 '17 at 04:15
  • @deribert mlocate developer (Miloslav Trmac) just told me about [this recently change](https://bugzilla.redhat.com/show_bug.cgi?id=1468131#c1). I think is very useful for people to know official sites of projects in order to let them get involve. I would be happy to suggest an edit if you think so. – Pablo A Jul 08 '17 at 04:18
4

Use find

find /path/to/dir -type f -name filename
polym
  • 10,672
  • 9
  • 41
  • 65
  • thanx, unfortunately find doesn't use prebuilt database of files. Is there something like "locate" there that uses index ? – chubbyk Jun 15 '14 at 16:47
  • 1
    You can use `locate` by installing it on your debian distro as others suggested :) – polym Jun 15 '14 at 16:50
  • 1
    If you are searching only for the ones with a _database_ please edit your question to have more proper answers. Find is a valid alternative to locate in the terms of your actual answer. It can offer you results that locate cannot. – Hastur Jun 15 '14 at 19:31
  • also sometimes the database is old and locate can't find your file. So don't rely on locate. – polym Jun 15 '14 at 20:32
  • 2
    *"So don't rely on locate."* That's mediocre advice unless you have reason to think that file might be recent or already know where to look. A full-filesystem `find` (which is the proper equivalent to `locate`) is an inefficient process that will slam the disk cache and may take a considerable time to complete. – dmckee --- ex-moderator kitten Jun 15 '14 at 20:56
1

The Silver Searcher

I use it to look inside source code/files and this alias similar to mlocate for filenames:

alias superlocate='bash -xc '\''ag -g $0 --hidden'\''  2>/dev/null'

Notes

  • This and more probably could be accomplished with ripgrep.
  • Also, now become popular plocate, which is faster, but lacks of --transliterate option, which I found extremely useful.
  • A faster alternative to find could be fd
Pablo A
  • 2,307
  • 1
  • 22
  • 34