In Linux, we often look for a file, but we do not know where to put it, for this case, we can use the following commands to search for files:
Which: View the location of the executable file.
Whereis: View the location of the file.
Locate: View the file location with the database.
Find: Actual search hard Drive query file name.
Here, we focus on the Find command:
Find command:
1. Command function:
The Find directive is used primarily to locate files, search for files in the file tree (directory structure), and perform the specified actions.
2. Command format:
Find Pathname-options [-print-exec-ok ...]
3. Command parameters:
The directory path that the Pathname:find command looks for. Use. To represent the current directory, and/to represent the system root directory.
The-print:find command outputs the matched file to standard output.
The-exec:find command executes the shell command given by the parameter to the matching file.
-ok: The same as-exec, except that the shell command given by this parameter is executed in a more secure mode, and before each command is executed, a
Let the user determine whether to execute.
4. Command options:
-name find files by file name.?
-perm follow file permissions to find files.
-prune Use this option to have the Find command not be found in the currently specified directory, and if you use the-depth option at the same time,-prune will be ignored by the Find command.
-depth: When looking for a piece, find the file in the current record and then in its?? Search in the record. ?
-user Search for files according to the owner of the file.
-group finds files according to the group to which the files belong.
-mtime-n +n The file changes time to find the file,-n means that the file change time is now less than n days, + n means that the file change time is now n days to
Ago. The Find command also has the-atime and-ctime options, but they are all the same as the-mtime option.
-type find a file of a certain type, such as:?
B-block device files.?
D-Directory.?
C-character device files.?
P-piping file.?
L-Symbolic link file.?
F-Normal file.
-size N: [C] finds files with a file length of n blocks, with C indicating the length of the file in bytes.
5. Execution of commands
(1) Name
Search for files of that name by searching for the file name Sun.txt:
(2)-perm
Search for files by searching for file permissions, the following example is a file with a search permission of 664:
(3)-group
To search for a file by searching for a file's owning group, the following example searches for a file that belongs to the root group:
(4)-user
The owner of the multi-search file searches for files, and the following example searches for files with the owner as root:
(5)-depth
Search file depth by searching for files The following example searches for files with a maximum depth of 3, named makefile
(6)-mtime,-atime,-ctime-n +n
Search files by-mtime,-atime,-ctime searching for documents The following example searches for files that change time within two days from now:
(7)-type
Search files by search file type the following example searches for files of the file type as normal files:
(b-Block device files,? d-Directories, C-character device files, p-pipe files, l-Symbolic link files, f-normal files.) )
(8)-size N[c]
Find files with a file length of n blocks, with C indicating that the file length is in bytes. The following files are searched for lengths of 5000k:
Linux-find command