Linux command --find

find is a very powerful command based on search. Relatively speaking, its use is relatively complicated and there are many parameters, so I will list them in categories here.

1. Basic grammar:

find [PATH] [option] [action]

2. Time-related parameters


-mtime n: n is a number, which means files that have been changed "within one day" n days ago;
-mtime +n: lists the file names that have been changed n days ago (not including n days itself);
-mtime -n: List file names that have been changed within n days (including n days itself);
-newer file: List file names that are newer than file

# E.g:

find /root -mtime 0 # 在当前目录下查找今天之内有改动的文件

3. Parameters related to the user or user group name


-user name: list files whose owner is name
-group name: list files whose user group is name
-uid n: list files whose owner is user ID n
-gid n: list files The user group belongs to the file with user group ID n
-nouser: Find the owner of the file who does not exist in /etc/passwd!
-nogroup: Find files whose owning group does not exist in /etc/group!

# E.g:

find /home/ljianhui -user ljianhui # 在目录/home/ljianhui中找出所有者为ljianhui的文件

4. Parameters related to file permissions and names


 -name filename: Search for files whose file name is filename (wildcards can be used)
   -size [+-]SIZE: Search for files larger (+) or smaller (-) than SIZE. The SIZE specifications are:
       c: represents byte
       k: represents 1024bytes. Therefore, to find a file larger than 50KB is "-size +50k"
   -type TYPE: The type of the search file is TYPE, and the main types are:
       general regular files (f)
       device files (b, c)
       directories ( d)
       Link file (l)
       socket (s)
       FIFO (p)
   -perm mode: Search for files with file permissions "just equal to" mode. This mode is an attribute value similar to chmod, for example, -rwsr-xr-x The attribute is 4755!
   -perm -mode: Search for files with file permissions "must include all mode permissions". For example,
       we want to search for files with -rwxr--r-- which is 0744, and use -perm -0744, as a file When the permission is -rwsr-xr-x, that is, 4755, it will also be listed, because the attributes of -rwsr-xr-x already include the attributes of -rwxr--r--.
   -perm +mode: Search for files with file permissions "including the permissions of any mode", for example
       Say, when we search for -rwxr-xr-x, that is, -perm +755, but a file attribute of -rw------- will also be listed because it has the attribute of -rw.... exist!

# E.g:

find / -name passwd # 查找文件名为passwd的文件
find . -perm 0755 # 查找当前目录中文件权限的0755的文件
find . -size +12k # 查找当前目录中大于12KB的文件,注意c表示byte

5. Additional actions that can be performed


   -exec command: command is other commands, additional commands can be followed by -exec to process the searched results.
   -print: Print the result to the screen. This action is the default action.
   | The default front output of xargs -i is replaced by {}.
   
# E.g:

     find / -perm +7000 -exec ls -l {} ; ,额外指令以-exec开头,以;结尾{}代替前面找到的内容
     find . -name "*.log" | xargs -i mv {} test4

 

 


 

Guess you like

Origin blog.csdn.net/xiao__jia__jia/article/details/114229047