Original link: http://www.ruanyifeng.com/blog/2009/10/5_ways_to_search_for_files_using_the_terminal.html
1. Find
Find is the most common and powerful look-up command you can use to find any file you're looking for.
Find uses the following format:
$ find < Specify directory > < specify conditions > < specify Actions >
-< specified directory;: the directory to be searched and all its subdirectories. The current directory is assumed by default.
-< specified conditions;: The characteristics of the file to be searched.
-< specify actions;: Specific processing of search results.
If no parameters are added, find searches the current directory and its subdirectories by default, and does not filter any results (that is, all files are returned) and displays them all on the screen.
Examples of use of find:
$ find. -name ' my* '
Searches the current directory (with subdirectories, below), with all files with the file name beginning with my.
$ find. -name ' my* '-ls
Searches the current directory for all file names that begin with my, and displays their details.
$ find. -type f-mmin-10
Searches the current directory for all the normal files that have been updated in the last 10 minutes. If you do not add the-type f parameter, search for normal files + special files + directories.
2. Locate
The locate command is actually another way of writing "Find-name", but much faster than the latter because it does not search for a specific directory, but instead searches for a database (/var/lib/locatedb), which contains all the local file information. The Linux system automatically creates this database and updates it automatically once a day, so you can't find the latest changed files using the Locate command. To avoid this situation, you can manually update the database by using the UpdateDB command before using locate.
Examples of use of the Locate command:
$ locate/etc/sh
Search all files in the ETC directory that begin with SH.
$ locate ~/m
Search for all files that start with M in the user's home directory.
$ locate-i ~/m
Searches all files that begin 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 binary files (parameter-B), man description file (parameter-m), and source code file (parameter-s) are searched. If the argument is omitted, all information is returned.
Examples of use of the Whereis command:
$ whereis grep
4. Which
The purpose of the 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. That is, with the which command, you can see whether a system command exists, and the command that executes exactly which location.
Examples of use of the which command:
$ which grep
5. Type
The type command is not actually a lookup command, it is used to distinguish whether a command is brought by the shell or by a standalone binary file outside the shell. If a command is an external command, then using the-p parameter displays the path to the command, which is equivalent to the which command.
Use instances of the type command:
$ type cd
The system will prompt that the CD is the Shell's own command (build-in).
$ type grep
The system prompts that grep is an external command and displays the path to the command.
$ type-p grep
When you add the-p parameter, it is equivalent to the which command.
Linux Find File command "Go"