Linux locate not found

-bash: locate: command not found

When you are running commands on Linux, Unix or Mac OS system terminals, sometimes you will encounter the command not found error. All users and systems are different and the issue could be a number of different things.

Some of the reasons why you are getting locate: command not found could be:

  • The command is misspelled (yes it does happen)
  • The command or package isn’t installed on the system
  • The location of the script or package is unknown

Lets go into detail on the different ways we can fix locate: command not found.

Method 1: Double check the command name

We make mistakes as humans and can easily misspell words or commands. Maybe you accidentally hit an extra word or added an unneeded space in the command.

Method 2: Make sure the command is installed on your system

Linux and Mac OS systems come with a lot of most common and popular packages or commands installed by default, but there are some versions that might be slimmed down a bit due to size and performance.

If your system doesn’t have a package or command installed, your package manager will be able to find a suitable package for your machine.

To install locate on Ubuntu Linux systems, you can try running the command:

To install locate on CentOS or Redhat Linux systems, you can try running the command:

Or for newer CentOS and Redhat systems, you can use the new DNF (Dandified YUM) command:

To install locate on Mac OS, you can try running the command:

Method 3: Make sure the path is set correctly

One of the most common mistakes is not setting the path for Linux or Mac OS packages. You need to let the shell prompt know the full absolute path of the script or add it to your PATH.

The PATH variable contains a list of directories with binary and executable files and commands. When you run a command, it checks to see if it exists in one of those PATH directories to run it.

Читайте также:  Acpi osi linux grub

To check the path or location of a command you can use the which command:

which ls to find the where the ls command is located.

which locate to find where locate is located.

If you want to run locate anywhere on your system, then you need to add it to your PATH:

You can add your package or script into one of those directories.

Or you can add a PATH to another directory that already contains your executable:

In this tutorial, you have learned how to fix the locate: command not found error.

If you found this help, please leave a comment below.

Related package errors

Источник

How to Install ‘locate Command’ to Find Files in Linux

The locate is a command line utility for finding files by name in Linux, just like find command. However, it works more efficiently compared to its counterpart; it uses one or more databases populated by the updatedb program and prints file names matching at least one of the patterns (a user provides) to standard output.

Locate package is provided by the GNU findutils or mlocate packages. These packages are known to provide the same implementation of the program. On most CentOS/RHEL systems, findutils comes pre-installed, however, if you try to run a locate command, you may encounter the error:

-bash: locate: command not found

In this article, we will show you how to install mlocate package which provides the locate and updatedb commands to find files in Linux systems.

Below is a sample output showing the above error and querying findutils package.

$ locate bash_completion.sh $ rpm -qa | grep findutils

Locate Command Not Found

To install mlocate, use the YUM or APT package manager as per your Linux distribution as shown.

$ sudo yum install mlocate [On CentOS/RHEL] $ sudo apt install mlocate [On Debian/Ubuntu]

After installing mlocate, you need to update the updatedb, which is used by locate command as root user with the sudo command, otherwise you will get an error. The default database storage location is /var/lib/mlocate/mlocate.db.

Once the database is updated, now try to run the locate command, which should work this time around.

Find Files Using Locate Command

To find an exact match according to pattern you enter, use this -b option and the \ globbing option as in the following syntax.

$ locate -b '\bash_completion.sh'

Note: You can use the LOCATE_PATH environmental variable to set a path to extra databases, which are read after the default database or any databases listed using the –database flag on the command line.

Читайте также:  Linux dialog select file

That’s all! In this guide, we showed you how to install mlocate package which offers the locate and updatedb commands on a Linux system. Share your views with us through the feedback form below.

Источник

locate: command not found

Sometimes, you create a file and forget wherein the directory structure you put it. Sometimes you don’t know the exact location of files created by the system, applications, or other users. In Linux, you have several powerful tools for finding the files you’re looking for.

The locate Command

The locate command quickly searches for any specified string in file names and paths stored in the mlocate database. This database must be updated regularly for the search to be effective. The results displayed may be restricted to files that users have permission to access or execute.

Syntax

The syntax of the locate command is:

If you encounter the below error while running the locate command:

you may try installing the below package as per the choice of your distribution:

Distribution Command
Debian apt-get install mlocate
Ubuntu apt-get install mlocate
Alpine apk add mlocate
Arch Linux pacman -S mlocate
Kali Linux apt-get install mlocate
CentOS yum install mlocate
Fedora dnf install mlocate
Raspbian apt-get install mlocate

locate Command Options

The locate command supports different options that enable you to make your search more effective. Some of the options are described in the table.

Option Used To
-r Search for file names using regular expressions.
-c Display only the number of matching entries found, rather than the file names.
-e Return only files that exist at the time of search.
-i Ignore the casing in file names or paths.
-n Return only the first few matches up to the specified number.

locate Command Examples

2. To match only the basename against the pattern:

# locate -b file.txt # locate --basename file.txt

3. To get the counts for matching entries:

# locate -c file.txt # locate --count file.txt

4. To replace the default database with the given:

# locate -d # locate --database

5. To print the entries that exist at the time when locate was fired:

# locate -e filename # locate --existing filename

6. To follow trailing symbolic links:

# locate -L text # locate --follow text

8. To exit successfully after finding a specified number of entries:

# locate -l 10 text # locate -n 10 text # locate --limit 10 text

9. To avoid following symbolic links:

# locate -P text # locate --nofollow text # locate -H text

10. To separate the output entries by ASCI NULL character:

# locate -0 text # locate --null text

11. To get the statistics about the read database:

# locate -S text # locate --statistics text

12. To suppress any errors if occurred:

# locate -q text # locate --quiet text

13. To get the version info:

14. To match the whole pathname:

# locate -w text # locate --wholename text

Источник

Ubuntu 19.10: why is the «locate» command missing?

So I installed mlocate and now locate works. As far as I can remember, since Ubuntu 11.04, locate has always been there. Why was it excluded in Ubuntu 19.10?

1 Answer 1

There was this thread: mlocate — what is it good for? with this:

The Ubuntu Foundations team was recently looking at an issue with mlocate[1] and the effect it has on all users of Ubuntu. While that specific issue is fixable there are also issues[2,3] with keeping PRUNEFS and PRUNEPATHS current in updatedb.conf. So we ended up questioning the usefulness of installing mlocate by default on systems at all. We believe that find is an adequate replacement for mlocate .

This initial post called for opinions on the matter.

Later, in the same thread, there’s this:

My own sense is that this is not a server vs desktop thing; there are users of locate, to be sure, but I believe they are a very small minority on both desktop and server (small on desktop because the user will generally use the gui instead; small on server because most server use is not interactive at the shell). I don’t think the benefit of having locate available by default justifies the daily disk thrashing / energy usage on every Ubuntu machine everywhere. I think it’s not onerous for those who want to use locate to manually install it the first time they need it on a machine.

Well, I don’t think this is an argument for keeping mlocate installed by default on desktops, because effectively this means that you have TWO indexers on your desktop system — both tracker and mlocate. It looks like nautilus currently depends on tracker, so I’m not sure how one would uninstall it and usefully fall back to the mlocate backend anyway, but at most I’d say this should be expressed as ‘Depends: tracker | mlocate’ in nautilus, and not have mlocate kept around on the system updating its database daily just in case a user removes tracker.

The bottom line is that if you want it, just install it.

Источник

Оцените статью
Adblock
detector