The Linux find command is a very effective tool that can traverse the current directory or even the entire file system to find some files or directories.
Main options of the Linux find command:
-Name: searches for files by file name
-Perm searches for Objects Based on file permissions.
-Prune is not found in the specified directory.
-The user searches for files based on the file owner.
-Group: searches for files based on the group to which the files belong.
-Mtime-N + N: Find the file based on the file change time.-N indicates that the file change time is earlier than N days, and + N indicates that the file change time is earlier than N days.
-Nogroup: Find the file with no valid group, that is, the group to which the file belongs does not exist.
-Nouser: Search for files without a valid owner
-Newer file1! File2 searches for files whose change time is newer than file1 but older than file2.
-Type: search for a certain type of file
[File type:
Block B Device Files
D directory
C character Device File
P MPs queue File
L symbolic link file
F common file]
-Size N [c]: searches for files with a file length of N blocks. If the file contains C, the file length is measured in bytes.
-When searching for files, depth first searches for files in the current directory, and then searches for files in its subdirectories.
-Mount does not span the mount point of the file system when searching for files.
-Follow: If the find command encounters a symbolic link file, it will trace the file pointed to by the link.
-Cpio: Use the cpio command to back up the files to the disk device.
(For other options, see man find)
Some examples of Linux find Command Options:
$ Find/etc-type D # search all directories under the/e t c directory
$ Find/etc-user yaoyuan # Find the file whose owner is yaoyuan in the/etc directory
$ Find.-size + 000000c # search for files with a length greater than 1 MB in the current directory
The whereis command searches for qualified files in the specified directory. The attributes of the files should belong to the original code, binary files, or help files.
Option:
-B: Only query binary files.
-B only searches for binary files in the Set Directory
-F does not display the path name before the file name
-M: only find the instruction file.
-M: only find the instruction file in the specified directory.
-S: Only search for original code files
-S: Only search for the original code file in the Set Directory
-U: Find Files that do not contain the specified type
Whereis example
$ Whereis MySQL
MySQL:/usr/bin/MySQL/etc/MySQL/usr/share/man/Man1/mysql.1.gz
The locate command is used to find the files that meet the conditions. It stores the files and directories in the database with the directory name and finds the files or directories that meet the conditions.
Option:
-U: Create a database starting from the root directory.
-U: You can specify the start location to create a database.
-E will be excluded from the search range
-F exclude a specific File System
-Q quiet mode, no error message is displayed
-N: display up to N outputs
-R: Conditions for searching using regular expressions
-O: Specifies the data inventory name.
-D specifies the database path
-H: displays the secondary message
-V: show more messages
-V: displays the version information of the program.
(The locate command can be used to quickly locate the file when searching the database. The database is updated by the updatedb program, and the updatedb is by cron.
Daemon is periodically created. The locate command is faster than the entire hard disk data to search for data in the database. However, the worst case is that the files found by the locate are created only recently or
The new name may not be found. In the specified value, updatedb runs once a day. You can modify crontab to update the value. (Etc/crontab)
Locate is used to search for qualified files. It stores the files and directories in the database to find files or directories that meet the template style conditions, special characters (such "*"
Or "? ", Etc.) to specify the template style, for example, to specify the template as the kcpa * NER,
Locate will find all the files or directories whose start string is kcpa and end with ner. If the name is kcpartner and the directory name is kcpa_ner
All files including sub-directories. )
Example of locate:
$ Locate inittab
/Usr/lib/upstart/migrate-inittab.pl
/Usr/share/terminfo/A/ANSI + inittabs
The above is a summary of the Linux find command whereis locate in Linux.