Linux系统文件中常用属性包括以下内容:名称,大小,权限,属主,属组,修改时间,访问时间等。在庞大的Linux系统中查询文件,需要借助查找工具来实现,依此可以查询相同或指定属性的文件,本文所讲的查询工具为find。
当我们使用普通用户权限去查找时,一些被ROOT用户设置禁止访问的文件会出现禁止访问字样,这个输出会导致想要的文件不好找。为了避免这样的错误,我们使用重定向的方法把错误提示转移。
转移前:
转移后:
1 以文件名查找
-name pattern 以文件名查找
2 以文件从属关系查找
-user USERNAME 以用户名查找
-group GROUPNAME 以组名查找
-uid UID 以UID号查找
-gid GID 以GID查找
-nouser 查找没有属性的文件
-nogroup 查找没有属组的文件
3 以文件类型查找
-type TYPE 以文件类型查找
f | d | b | c | l | s | p |
---|---|---|---|---|---|---|
普通文件 | 目录文件 | 块设备文件 | 字符设备文件 | 连接文件 | 套接字文件 | 管道文件 |
4 根据文件大小查找
-size [+|-]SIZE 以文件大小查询,单位包括K,M,G。
-size 5M 精确查找大小为5M的文件,大小稍有偏差
-size -5M 查询大小小于5M的文件
-size +5M 查询大小大于5M的文件
5 根据时间查找
-atime [+|-]TIME : 以访问时间(天)查找
-mtime [+|-]TIME : 以数据修改时间(天)查找
-ctime [+|-]TIME : 以元数据修改时间(天)查找
-amin [+|-]TIME : 以访问时间(分钟)查找
-mmin [+|-]TIME : 以数据修改时间(分钟)查找
-cmin [+|-]TIME : 以元数据修改时间(分钟)查找
-newer FILE : 以FILE文件为条件,判断比它新的文件
7 : 准确时间,7表示刚好7(天|分钟)起始位置
+7: 7(天|分钟)以前的
-7: 7(天|分钟)以内的