Find
Find is a very effective tool that can traverse the current directory and even the entire file system to find certain files or directories.
Main option:-namefind files by file name-permfollow file permissions to find files-prunedoes not find in the currently specified directory-userFind files According to the owner of the file-groupfind a file by the group to which it belongs-mtime-n +naccording to the file change time to find the file,-n means that the file change time is less than n days, +n indicates that the file change time is now N days ago.-nogroupfind a file that does not have a valid owning group, that is, the group to which the file belongs does not exist-nouserfind files with no valid owner-newer file1! File2look for changed times than files File1 new but older files than files File2-typefind a file of a certain type
[file type: theBBlock device FilesDCatalogueCCharacter device FilesPPipeline FilesLSymbolic Link FileFNormal file]
-size N[c]Find files with a file length of n blocks, with C indicating the length of the file in bytes-depthwhen looking for a file, first find the file in the current directory, and then look in its subdirectories-mountdo not cross file system mount points when locating files-followif the find command encounters a symbolic link file, it tracks the file that the link points to-cpiouse the Cpio command with the matching files to back up these files to the disk device
(The remaining options, please man find, see further) Some examples of the Find command options: $ find/etc-type D# Find all the directories in the/etc directory$ find/etc-user Yaoyuan# Find files in the/etc directory where the file belongs to the main Yaoyuan$ find. -size +1000000c# Find files with file lengths greater than 1 m bytes in the current directory
WhereisThe Whereis command looks for the eligible files in the specified directory, and the file should be of the original code, binary, or help file.
Option:-Bfind only binary files-Bfind binary files only in the directory you set-Fpath name before file name is displayed-MFind a description file only-MFind a description file only in the directory you set-Sfind only original code files-Sfind the original code file only in the directory you set-Ufind files that do not contain the specified type
Whereis example $ whereis mysql MySQL:/usr/bin/mysql/etc/mysql/usr/share/mysql/usr/share/man/man1/mysql.1.gz
LocateThe locate command is used to find a file that matches a condition, and it goes to the database where the file and directory names are saved, to find a file or directory that matches the criteria
Option:-Uset up the database, starting with the root directory-Uset up a database to specify where to start-Ewill be excluded from the scope of the search-Fexclusion of specific file systems-QQuiet mode, no error messages are displayed-Ndisplay up to n outputs-Rconditions for finding using regular expressions-OSpecify the name of the database storage-Dspecify the path to the database-HShow Auxiliary Messages-VShow more Messages-VDisplays the version message of the program
(Locate command can quickly find the file in the search database, the database is updated by the UpdateDB program, UpdateDB is built by cron Daemon, locate command in the search for the database than by the entire data from the hard disk to search for data come fast, But the worse is locate found the file if recently established or newly renamed, may not be found, in the default value, UpdateDB will run once a day, can be modified crontab to update the set value. (ETC/CRONTAB) Locate designated for the search of eligible files, it will be stored in the file and directory name of the database, to find matching template style conditions of the file or directory, you can use special characters (such as "*" or "?" And so on) to specify the template style, as specified by Kcpa*ner, locate will find all files or directories that have a starting string of KCPA and end with NER, such as the name Kcpartner if the directory name is Kcpa_ner, all files including subdirectories are listed under that directory. )
Locate Example:
$ locate Inittab/usr/lib/upstart/migrate-inittab.pl/usr/share/terminfo/a/ansi+inittabs
whichWhich and where are similar, just the set of environment variables we set in the path to find;
[email protected] ~]# which fdisk
/sbin/fdisk
=============================================================================================================
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, Whereis, locate, which lookup File command summary-from Cyber