Find the difference between find, locate, whereis, which, type in linux

  
        

Find the command find, locate, whereis, which, type difference in linux

1. find

Java code

find is the most common and powerful search Command, you can use it to find any file you are looking for. Unlike the query database (/var/lib/locatedb) file, find finds disk space

find uses the following format:

$ find <specified directory> <specified condition> <Specify Action>

- <Specify Directory>: The directory to be searched and all its subdirectories. The default is the current directory.

- <Specify Condition>: The characteristics of the file to be searched.

- <Specify action>: Perform specific processing on search results.

If nothing is added, find defaults to the current directory and its subdirectories, and does not filter any results (that is, returns all files), displaying them all on the screen.

Use examples of find:

$ find . -name 'my*'

Search the current directory (including subdirectories, the same below), all file names are my The beginning of the file.

$ find . -name 'my*' -ls

Searches for files in the current directory with all file names starting with my and displays their details.

$ find . -type f -mmin -10

Searches for all the regular files that have been updated in the past 10 minutes in the current directory. If the -type f parameter is not added, the normal file + special file + directory is searched.

2. locate

Java code

The locate command is actually another way of writing "find -name", but it is much faster than the latter because Instead of searching for a specific directory, it searches for a database (/var/lib/locatedb) that contains all local file information. The Linux system automatically creates this database and automatically updates it once a day, so you can't find the latest changed files using the locate command. To avoid this, you can manually update the database using the updatedb command before using locate.

Use examples of the locate command:

$ locate /etc/sh

Search for all files starting with sh in the etc directory.

$ locate ~/m

Search all files starting with m in the user's home directory.

$ locate -i ~/m

Searches for all files starting with m in the user's home directory, and ignores case.

3. whereis

Java code

The whereis command can only be used for program name search, and only search binary files (parameter-b), man description file (parameters) -m) and source code file (parameter -s). If the parameter is omitted, all information is returned. As with locate, query the database (/var/lib/locatedb) file

use instance of the whereis command:

$ whereis grep

4. which

Java code

The purpose of which command is to search for the location of a system command in the path specified by the PATH variable and return the first search result. In other words, using the which command, you can see if a system command exists and which command is executed.

Use example of which command:

$ which grep

5. type

Java code

type command can't be found Command, which is used to distinguish whether a command is provided by the shell or by a separate binary file outside the shell. If a command is an external command, then using the -p parameter will display the path to the command, which is equivalent to the which command.

Use example of type command:

$ type cd

The system will prompt, cd is the shell's own command (build-in).

$ type grep

The system prompts that grep is an external command and shows the path to the command.

$ type -p grep

After adding the -p parameter, it is equivalent to the which command

Copyright © Windows knowledge All Rights Reserved