Linux find command learning

The find command works as follows: it traverses down the file hierarchy, matches files that meet the criteria, and performs the appropriate action.

 

  The argument to the option -name specifies the string that the filename must match. We can use wildcards as parameters.

  The -iname parameter ignores case.

  If you want to match one of multiple conditions, you can use the OR conditional operation:

  If it is the condition of and, you can write nothing or -and.

  The option -path can use wildcards to match file paths or files. -path Match file paths as a whole.

  The option -regex matches file paths based on regular expressions.

  Can use! The meaning of the negated parameter.

  The find command traverses all subdirectories when used. We can take some depth parameters to limit the depth the find command traverses. -maxdepth and -mindepth are such parameters.

If you only need to retrieve in the current directory, you can set the maximum depth - maxdepth to 1:

The minimum depth -mindepth can be used to find all files that are more than a certain depth from the starting path.

 

  The -type option can search by file type.

The following table shows all file type parameters:

file type type parameter
normal file f
symbolic link l
content d
character device c
block device b
socket s
Fifo p

 

  Every file in a Linux file system has three timestamps, as follows:

· Access time (-atime): The last time the user accessed the file.

Modification time (-mtime): The last time the file content was modified.

Change time (-ctime): The last time the file metadata was changed.

There is no concept of so called "creation time" in Linux.

-atime, -mtime, -ctime can be used as time options for find, and they can be given as integer values ​​in days. A plus or minus sign can be added before the value to indicate how many days it is greater or less than.

The three lines of commands in the above figure represent three situations: visited within 7 days, visited 7 days ago, and visited exactly 7 days ago.

The corresponding -amin, -mmin, -cmin are used to indicate minutes.

  The -newer parameter can find all files newer than the reference file.

  The option -size can search based on the size of the file.

  在find命令最后加上-delete选项可以删除查找到的匹配文件。

  选项-perm可以匹配特定权限的文件:

 

  -exec选项可以让find和其他命令一起执行:

-exec还可以执行sh文件:

注意:查找到多少个文件就执行sh文件多少遍。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326350702&siteId=291194637