11

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

What's the alternative for this command on Debian ?

0
30

I recommend locate.

sudo apt-get install locate
2
  • 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. 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.

1
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).

3
  • pagure.io/mlocate is the new official home site of mlocate.
    – Pablo A
    Jul 8 '17 at 3: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 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 bugs.debian.org/cgi-bin/bugreport.cgi?bug=867640
    – derobert
    Jul 8 '17 at 4:15
  • @deribert mlocate developer (Miloslav Trmac) just told me about this recently change. 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 8 '17 at 4:18
4

Use find

find /path/to/dir -type f -name filename
5
  • 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. Jun 15 '14 at 20:56
1

I use The Silver Searcher 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'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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