What is the Linux Find File command?

  
                

In the Linux system, there are a total of 5 commands for finding files, but generally only two to three of them are used. You can use the find command to quickly find any files you want to find. Let's go.

1. find

find is the most common and most powerful Find command, you can use it to find any file you are looking for.

The format of find is as follows:

$ find "specified directory" "specified condition" "specified action"

- "specified directory": the directory to be searched and All subdirectories. The default is the current directory.

- "Specified Conditions": The characteristics of the file to be searched.

- "Specified Action": Specific processing of 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*’

Searches for the current directory (including subdirectories, the same below), all files whose names begin with my.

$ find . -name ‘my*’ -ls

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

$ find . -type f -mmin -10

Searches for all 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

The locate command is actually another way of writing "find -name", but it is much faster than the latter because it does not search for specific directories, but instead Search 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

The whereis command can only be used for program name searches, and only searches for binary files (parameter -b), man documentation (parameter -m), and source code files ( Parameter -s). If the parameter is omitted, all information is returned.

Use examples of the whereis command:

$ whereis grep

4. which

The role of which command is, in the path specified by the PATH variable, Search for the location of a system command 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

The type command can't be used as a find command, it is used to distinguish a certain Whether the commands are provided by the shell or by independent binary files 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.

The above is the introduction of the Linux lookup command. The main search commands are all these. Remember that it is completely sufficient. If you are still worried about finding files, these commands will solve your problem.

Copyright © Windows knowledge All Rights Reserved