Linux-find command
The Linux Find command searches the directory structure for the file, and the action specified by the line.
1. Command format:
find Pathname-options [-print-exec-ok ...]
2. Command function:
Used to find files in the file tree and to make appropriate processing.
3. Command parameters:
the directory path that the Pathname:find command looks for.
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, in the form of ' command ' {} \;
-ok: The same as-exec, except that the shell command given by the parameter is executed in a more secure mode, prompting the user to determine whether to execute before executing each command.
4. Usage examples:
Example 1: Find file -nameby file name.
Command:
Find. -name file.c
Output:
Example 2: Find files by file permissions -perm
Command:
Find. -perm 664
Output:
Example 3: find files by file depth -depth-maxdepth-mindepth
-depth when looking for a file, first find the file in the current directory, and then look in its subdirectories.
Description: Find.-depth-name "File" –print it will first match all the files and then go to the subdirectory to find file.
Command: Find. -maxdepth 3-name "file*"
Output:
Example 4: find files by file owner and owning group -user-group
-user Find Files according to the owner of the file
-group finds files according to the group to which the files belong.
command:
Find. -user Root
Find. _group Root
Output:
Example 5: Find files by file time -mtime-ctime-atime
-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 indicates that the file change time is now N days ago.
The Find command also has the-atime and-ctime options, but they are all similar to the-mtime option, so we'll just cover the-mtime option here
Command:
Find. -mtime-3
Output:
Example 6: Find Files by file type -type
File types such as: B-block device files; D-directories; C-character device files; p-pipe files; L-symbol link files; F-common files; s-socket files.
Command:
Find. -type F
Output:
Example 7: find files by file size -size n[c]
-size N[c] finds files with a file length of n blocks, with C indicating the length of the file in bytes.
Command:
Find. -size +50k
Output:
Linux-find command