关于我们

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻公共列表

Centos云服务器文件搜索命令的详细介绍

发布时间:2021/8/14 20:00:58
香港云服务器

1、locate--->文件查找事先生成的数据库,模糊查找,updatedb更新locate数据库

-i:忽略文件名的大小写

-n:只显示前n行eg:locate-n3passwd

2、find---->实时查找,精确匹配文件名

find[DIR...][CRIERIA][ACTION...]

DIR:/root/home..(默认当前目录)

ACTION;

-print(默认)

-ls

-okCOMMAND交互式执行命令

-execCOMMAND非交互式执行命令

xargs从标准输出中执行和创建命令

eg;find/root-name"[[:alpha:]][[:digit:]]"-execmv{}{}\;//{}代表前面查找的结果,后面必须用\;结尾

find/root-name"[[:alpha:]][[:digit:]]"|xargschmod755

CRIERIA:

-name:精确到指定的文件名

-iname:根据文件名查找,但不区分大小写

-user:根据属主查找

-group:根据属组查找

-uid:根据uid查找

-gid:根据gid查找

在指定时间段里查找:

-atime:[+/-]N(accesstime):+-表示---(+)----N---(-)----currentday

eg:find-atime-3-execls-l{}\;

-mtime:(modificationtime)同上

-ctime(changetime)同上

-amin以分种为单位,同上

-mmin

-cmin

-anewera.txt比a.txt更近的访问

eg:find-anewersh01.sh-execls-l{}\;

-newer相当于modificationtime

-cnewer相当于changetime

-type:按照类型查找

d(目录),l(链接文件),f(普通文件),s(套接文件),

b(块设备),c(字符设备),p(命令管道文件)

eg:find/var-typel-execls-l{}\;

-size:按照大小查找

[+/-]N

-perm[+/-]mode根据权限查找

mode755

-222每一类用户都要匹配

eg:find/tmp/myscrip-perm-001

/222某一个用户只要有一类权限的即可

-nouser:没有用户

eg:find/-nouser查看没有用户名的文件,一般这种文件有一定的危险性

-nogroup:没有组的

查找条件连接:

-a:&&通常可以省略

eg:find-userroot-typef-execls-dl{}\;

-o:||

eg:find-usernamed-o-typed-execls-ld{}\;

-notor!:!

eg:find-not\(-typed-a-userroot\)-execls-ld{}\;

-ls-l`find/-namepasswd`

文件名通配:*任意一个字符,?单个字符,[]

eg:find/tmp-namea*//查找以a开头的文件