Locate
Usage: Locate filename
Locate is a find (locate) file command in a Linux system, similar to finding a file, such as a Find command, but locate is created by generating an indexed database of files and folders, which is found directly in the index database when the user executes the locate command to find the file. If the database is too long to update or does not exist, you will be prompted when you find the file:
"Locate:can not open '/var/lib/mlocate/mlocate.db ': No such file or directory".
Execute "updatedb" at this time
Update the database.
Usage examples:
[Email protected] ~]$Locatea.txt/home/keysystem/a.txt/usr/share/doc/sane-backends-1.0. +/matsushita/Matsushita.txt/usr/share/doc/vim-common-7.2.411/Readme_extra.txt/usr/share/gnupg/Help.ca.txt/usr/share/gnupg/Help.da.txt/usr/share/gnupg/Help.ja.txt/usr/share/perl5/unicore/UnicodeData.txt/usr/share/vim/vim72/doc/ft_ada.txt.gz/usr/share/vim/vim72/doc/os_amiga.txt.gz/usr/share/vim/vim72/doc/Uganda.txt.gz[[email protected]~]$
Find
The Find command is a ubiquitous command and is one of the most useful commands in Linux. The Find command is used to search for files in a directory (and subdirectories), and you can specify some matching criteria, such as locating files by file name, file type, user, or even time stamp. Here's an example of the power of the Find command.
Usage: Find
The general form of the find command given in the man document is:
Find [-h] [-l] [-p] [-D debugopts] [-olevel] [path ...] [Expression]
In fact [-h] [-l] [-p] [-D debugopts] [-olevel] These options are not commonly used (at least in my daily work, not used), the above the common form of the Find command can be simplified to:
Find [path ...] [Expression]
- The directory path that the Path:find command looks for. For example, use. To represent the current directory, and/to represent the system root directory
- Expression:expression can be divided into--"-options [-print-exec-ok ...]"
- -options, specify common options for the Find command, and the following section details
- The-print,find command outputs the matched file to the standard output
- The-exec,find command executes the shell command given by the parameter to the matching file. The corresponding command is in the form of ' command ' {} \;, note the space between {} and \;
Find./-size 0-exec rm {} \; Delete files with a file size of zero (you can also do this: Rm-i ' find./-size 0 ' or find./-size 0 | Xargs Rm-f &)
Example of the Find command:
find . -type F. /out.put. /file. /file1. /file2. /b.txt. /files.txt. /
# #查找当前目录下类型是目录的
find . -type D.. /Hello. /world
# #查找当前目录下类型是文件的 and LS-l View File {} represents the file name found earlier [[email protected] redirect]$Find. -type f-execls-l ' {} '';'-rw-rw-r--.1Keysystem Keysystem -Dec3 +: $./Out.put-rw-rw-r--.1Keysystem Keysystem ADec3 +: +./file-rw-rw-r--.1Keysystem Keysystem6Dec3 +: to./file1-rw-rw-r--.1Keysystem Keysystem6Dec3 +: to./file2-rw-rw-r--.1Keysystem Keysystem toDec3 +: the./files.txt
The ##-printfind command outputs the matched file to the standard output
[Email protected] redirect]$Find. -type f-execls-L {}';'-Print-rw-rw-r--.1Keysystem Keysystem -Dec3 +: $./Out.put./Out.put-rw-rw-r--.1Keysystem Keysystem ADec3 +: +./file./file-rw-rw-r--.1Keysystem Keysystem6Dec3 +: to./file1./file1-rw-rw-r--.1Keysystem Keysystem6Dec3 +: to./file2./file2-rw-rw-r--.1Keysystem Keysystem toDec3 +: the./Files.txt./files.txt
Find grep ' {}'; ' -Printhello. /filehello. /File1hello. /a.txt
# #查找文件中包含Hello的 and Print travel number-n indicates the line number [[email protected] redirect]$Find. -type f-execgrep-N Hello'{}' ';'-Print1: Hello./b.txt# #查找文件中包含Hello的 and print travel numbers-N denotes line number-I means ignore case [[email protected] redirect]$Find. -type f-execgrep-ni Hello'{}' ';'-Print1: Hello./file1: Hello./file11: Hello./B.txt1: Hello./a.txt
Happygrep
Find on Linux