[Linux] the most complete history of the Find command

Find


Function Description : Find the file or directory.

Syntax: find (- $)

Parameter Description:

[目录...]
[-amin <分钟>]                          查找在指定时间曾被存取过的文件或目录,单位以分钟计算
[-anewer <参考文件或目录>]               查找其存取时间较指定文件或目录的存取时间更接近现在的文件或目录
[-atime <24小时数>]                     查找在指定时间曾被存取过的文件或目录,单位以24小时计算
[-cmin <分钟>]                          查找在指定时间之时被更改的文件或目录    
[-cnewer <参考文件或目录>]               查找其更改时间较指定文件或目录的更改时间更接近现在的文件或目录
[-ctime <24小时数>]                     查找在指定时间之时被更改的文件或目录,单位以24小时计
[-daystart]                             从本日开始计算时间
[-depyh]                                从指定目录下最深层的子目录开始查找
[-empty]                                寻找文件大小为0 Byte的文件,或目录下没有任何子目录或文件的空目录
[-exec <执行指令>]                       假设find指令的回传值为True,就执行该指令
[-false]                                将find指令的回传值皆设为False
[-fls <列表文件>]                        此参数的效果和指定"-ls"参数类似,但会把结果保存为指定的列表文件
[-follow]                               排除符号连接
[-fprint <列表文件>]                    此参数的效果和指定"-print"参数类似,但会把结果保存成指定的列表文件
[-fprint0 <列表文件>]                   此参数的效果和指定"-print0"参数类似,但会把结果保存成指定的列表文件
[-fprintf <列表文件><输出格式>]         此参数的效果和指定"-printf"参数类似,但会把结果保存成指定的列表文件
[-fstype <文件系统类型>]                只寻找该文件系统类型下的文件或目录
[-gid <群组识别码>]                     查找符合指定之群组识别码的文件或目录
[-group <群组名称>]                     查找符合指定之群组名称的文件或目录
[-help]                                 在线帮助
[-ilname <范本样式>]                    此参数的效果和指定"-lname"参数类似,但忽略字符大小写的差别
[-iname <范本样式>]                     此参数的效果和指定"-name"参数类似,但忽略字符大小写的差别
[-inum <inode编号>]                     查找符合指定的inode编号的文件或目录                
[-ipath <范本样式>]                     此参数的效果和指定"-ipath"参数类似,但忽略字符大小写的差别
[-iregex <范本样式>]                    此参数的效果和指定"-regexe"参数类似,但忽略字符大小写的差别
[-links <连接数目>]                     查找符合指定的硬连接数目的文件或目录
[-lname <范本样式>]                     指定字符串作为寻找符号连接的范本样式
[-ls]                                   假设find指令的回传值为True,就将文件或目录名称列出到标准输出
[-maxdepth <目录层级>]                  设置最大目录层级
[-mindepth <目录层级>]                  设置最小目录层级
[-mmin <分钟>]                          查找在指定时间曾被更改过的文件或目录,单位以分钟计算
[-mount]                                此参数的效果和指定"-xdev"相同              
[-mtime <24小时数>]                     查找在指定时间曾被更改过的文件或目录,单位以24小时计算
[-name <范本样式>]                      指定字符串作为寻找文件或目录的范本样式
[-newer <参考文件或目录>]               查找其更改时间较指定文件或目录的更改时间更接近现在的文件或目录
[-nogroup]                              找出不属于本地主机群组识别码的文件或目录
[noleaf]                                不去考虑目录至少需拥有两个硬连接存在
[-nouser]                               找出不属于本地主机用户识别码的文件或目录
[-ok <执行指令>]                        此参数的效果和指定"-exec"参数类似,但在执行指令之前会先询问用户,若回答"y"或"Y",则放弃执行指令
[-path <范本样式>]                      指定字符串作为寻找目录的范本样式
[-perm <权限数值>]                      查找符合指定的权限数值的文件或目录
[-print]                                假设find指令的回传值为True,就将文件或目录名称列出到标准输出。格式为每列一个名称,每个名称之前皆有"./"字符串
[-print0]                               假设find指令的回传值为True,就将文件或目录名称列出到标准输出。格式为全部的名称皆在同一行
[-printf <输出格式>]                    假设find指令的回传值为True,就将文件或目录名称列出到标准输出。格式可以自行指定
[-prune]                                不寻找字符串作为寻找文件或目录的范本样式
[-regex <范本样式>]                     指定字符串作为寻找文件或目录的范本样式
[-size <文件大小>]                      查找符合指定的文件大小的文件
[-true]                                 将find指令的回传值皆设为True
[-type <文件类型>]                      只寻找符合指定的文件类型的文件
[-uid <用户识别码>]                     查找符合指定的用户识别码的文件或目录
[-used <日数>]                          查找文件或目录被更改之后在指定时间曾被存取过的文件或目录,单位以日计算
[-user <拥有者名称>]                    查找符合指定的拥有者名称的文件或目录
[-version]                              显示版本信息
[-xdev]                                 将范围局限在先行的文件系统中
[-xtype <文件类型>]                     此参数的效果和指定"-type"参数类似,差别在于它针对符号连接检查

Supplement: find instructions for finding qualified files. Any string parameters located before will be treated as a directory to be searched.

Examples

(1) Find a modified file within 48 hours

find -atime -2

(2) Find ending in .log files in the current directory. . "" Represents the current directory

find ./ -name '*.log'

(3) Find / opt directory permissions to 777 files

find /opt -perm 777

(4) Find files larger than 1K of

find -size +1000c

Find find -size 1000c equal to 1000 characters in file

     `-exec         参数后面跟的是command命令,它的终止是以;为结束标志的,所以这句命令后面的分号是不可缺少的,考虑到各个系统中分号会有不同的意义,所以前面加反斜杠。{}   花括号代表前面find查找出来的文件名。`

(5) Find change the time in the current directory in the previous 10 days files and delete them (No reminder)

find . -type f -mtime +10 -exec rm -f {} ;

(6) the current directory to find all files ending in .log, change file time in more than five days, and delete them, but to prompt before deleting. Press y to delete the file, press the delete key does n

find . -name '*.log' mtime +5 -ok -exec rm {} ;

Under (7) of the current directory to find the file name begins with passwd, content that contains "pkg" character file

find . -f -name 'passwd*' -exec grep "pkg" {} ;

(8) with the option to execute the cp command exec

find . -name '*.log' -exec cp {} test3 ;

     `-xargs find命令把匹配到的文件传递给xargs命令,而xargs命令每次只获取一部分文件而不是全部,不像-exec选项那样。这样它可以先处理最先获取的一部分文件,然后是下一批,并如此继续下去。`

(9) common to find each file in the current directory, and the file type is determined to xargs

find . -type f -print | xargs file

(10) Find all of the current common js files ending and contains the 'editor' character directory

find . -type f -name "*.js" -exec grep -lF 'ueditor' {} ;

find -type f -name '*.js' | xargs grep -lF 'editor'

(11) use xargs execute the command mv

find . -name "*.log" | xargs -i mv {} test4

(12) search using grep command in all the ordinary files in the current directory in hostnames of the word, and mark the row

find -name * (escape) -type f -print |. xargs grep -n 'hostnames'

(13) Find the current directory with a lowercase letter, and finally 4 to 9 .log file with the end of the

find . -name '[a-z]*[4-9].log' -print

(14) Find test4 not find a subdirectory in the test directory

find test -path 'test/test4' -prune -o -print

(15) Example 1: Change the time to find new but the old than the file log2012.log than the file log2017.log file

find -newer log2012.log ! -newer log2017.log

Use depth options :

When the depth option makes the find command to back up files on a tape system, I want to first back up all the files, and then followed by the backup files in subdirectories.

Examples :
the Find command to start from the root directory of the file system, look for a file named CON.FILE of. First, it will match all files and then re-enter the subdirectory Find

find / -name "CON.FILE" -depth -print

Guess you like

Origin www.cnblogs.com/BabySermonizer/p/11441231.html