Detailed description of parameters of linux find statement

Detailed explanation of find command in linux

Find a file
find ./ -type f

Find a directory
find ./ -type d

Find a file or directory named test
find ./ -name test

Find a file whose name matches a regular expression , pay attention to the preceding ' .* ' ( the found file with a directory )
find ./ -regex .*so.*\.gz

find a directory and list the files in the directory ( execute the ls command separately for each directory found , without the option -print , the previous line of the file list will not be Display the directory name )
find ./ -type d -print
-exec ls {} \; find the directory and list the files in the directory ( execute the ls command separately for each directory found, you need to confirm before executing the command ) find ./ - type d -ok ls {} \; find a directory and list the files under the directory ( add the found directory to ls




After the command is executed once, if the parameters are too long, it will be executed multiple times )
find ./ -type d -exec ls {} +

find the file whose file name matches *.c
find ./ -name \*.c

After printing the test file name , print the content of the test file
find ./ -name test -print -exec cat {} \;

do not print the test file name, only print the content of the test file
find ./ -name test -exec cat {} \;

find the file update date time is within two days of the current time. Find the file ./
-mtime
-2 Find the file update date and time Find the file more than two days away from the current time. file find ./ -mtime 2 find files whose update date is less than two minutes from the current time find ./ -mmin -2 find files whose update date is more than two minutes from the current time find ./ -mmin +2













查找文件更新日时在距现在时刻一分以上二分以内的文件
find ./ -mmin 2

查找文件更新时间比文件abc的内容更新时间新的文件
find ./ -newer abc

查找文件访问时间比文件abc的内容更新时间新的文件
find ./ -anewer abc

查找空文件或空目录
find ./ -empty

查找空文件并删除
find ./ -empty -type f -print -delete

查找权限为644的文件或目录(需完全符合)
find ./ -perm 664

查找用户/组权限为读写,其他用户权限为读(其他权限不限)的文件或目录
find ./ -perm -664

查找用户有写权限或者组用户有写权限的文件或目录
find ./ -perm /220
find ./ -perm /u+w,g+w
find ./ -perm /u=w,g=w

查找所有者权限有读权限的目录或文件
find ./ -perm -u=r

查找用户组权限有读权限的目录或文件
find ./ -perm -g=r

查找其它用户权限有读权限的目录或文件
find ./ -perm -o=r

查找所有者为lzj的文件或目录
find ./ -user lzj

查找组名为gname的文件或目录
find ./ -group gname

查找文件的用户ID不存在的文件
find ./ -nouser

查找文件的组ID不存在的文件
find ./ -nogroup

查找有执行权限但没有可读权限的文件
find ./ -executable \! -readable

查找文件size小于10个字节的文件或目录
find ./
-size -10c

查找文件size等于10个字节的文件或目录
find ./
-size 10c

查找文件size大于10个字节的文件或目录
find ./
-size +10c

查找文件size小于10k的文件或目录
find ./
-size -10k

查找文件size小于10M的文件或目录
find ./
-size -10M

查找文件size小于10G的文件或目录
find ./
-size -10G

 

 

Guess you like

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