Explain the find and locate commands for finding directories and files in Linux

  
find
find path-command parameters [output form]
Parameter description:
Path: tell find where to find what you want,
Command parameters: Many parameters will be mentioned below
Output form: There are many output forms, -print, -printf, -print0, -exec, -ok, -ls Anyway, look at the manual yourself.
Let's talk about exec,
-exec find command to execute other linux commands given by this parameter for matching files. The corresponding command is of the form 'command - and' {} \\;, note the spaces between { } and \\;.
-ok and - exec have the same effect, but only interact with the person. OK will confirm to you before execution.
The main parameters of the find command:
-name Find files by file name.
-perm Find files by file permissions.
-prune Use this option to make the find command not find in the currently specified directory. If the -depth option is used at the same time, the -prune option will be ignored by the find command.
-user Finds files by file owner.
-group Finds files according to the group to which the file belongs.
-mtime -n +n Find files according to the file change time, -n means that the file change time is within n days, and +n means the file change time is now n days ago. The find command has the -atime and -ctime options, but they are all similar to the -mtime option
, so we will only introduce the -mtime option here.
-nogroup Finds a file with no valid group, that is, the group to which the file belongs does not exist in /etc/groups.
-nouser Finds a file with no valid owner, ie the owner of the file does not exist in /etc/passwd.
-newer file1 ! file2 Finds files that are newer than file1 but older than file2.
-type Finds a file of a certain type, such as:
b - block device file.
d - directory.
c - Character device file.
p - Pipe file.
l - Symbolic link file.
f - Ordinary files.
s - socket file
-size n[c] Find files with a file length of n blocks, with c indicating that the file length is in bytes.
-depth When looking for a file, first look up the files in the current directory and then look in their subdirectories.
Copyright © Windows knowledge All Rights Reserved