The Linux file lookup related commands generally involve two commands:
Locate
Format:
Locate file name
Locate Regular expressions
Description
Instead of searching the file system, locate searches from a database. So the locate command searches very fast.
However, the locate command cannot find the new file that was just created. The information for the new file is not saved to the database in real time. With the UpdateDB command, the file system information is saved to the database, UpdateDB is usually run once a day.
The UpdateDB command can be run manually, but the UpdateDB command is only run by the root user.
Cases:
Locate VIMRC
Find
The Find command is used to find files in the current directory.
Cases:
Find all content in the current directory, including directories and files:
Find.
Find all txt files in the current directory:
Find. | grep. txt
Find all files in the current directory:
Find. -type F
Find all directories in the current directory:
Find. -type D
To execute a command against a collection of searched files:
Find. -type f-exec ls-l ' {} '; '
Content lookup for a collection of searched files:
Find. -type f-exec grep hello ' {} '; '
Find the contents of the searched file collection and output the file that matches the content:
find.-type f-exec grep hello ' {} '; ' -print
Finds the contents of the searched collection of files and outputs the file where the match is located, and outputs the line number of the matching content:
find.-type f-exec grep-n Hello ' {} '; ' -print
The search for a collection of files for content lookup, the content lookup ignores case, the output matches the file, and output the line number of matching content:
find.-type f-exec grep-ni Hello ' {} '; ' -print
Description
' {} ': Represents the result set of the Find command search.
The output of the Find command searches and outputs the memory in a depth-first manner.
Linux file Lookup