每天一个linux命令(find)

find----查找指定目录下的文件

格式:find [选项] [路径] [表达式]

主要作用:

1.搜索文件

常用表达式:

-mount,-xdev:只检查和指定目录在同一文件系统下的文件,避免列出其他文件系统中的文件

-amin [-,+]n:在过去n分钟内被读取过的文化,-表示之内,+表示之前

-atime [-,+]n:在过去n天内被读取过的文件,-表示之内,+表示之前

-anewer file:比file更晚被读取过的文件

-cnewer file:比文件file更新的文件

-cmin [-,+]n:在过去n分钟之内被修改过的文件,-表示之内,+表示之前

-ctime [-,+]n:在过去n天内被修改过的文件,-表示之内,+表示之前

-empty:

-ipath p :

-perm:按照文件权限查找文件

-name:按照文件名来查找文件

-size [-,+]n[c]:查找文件长度为n的文件,后面带c以字节计算,-表示小于,+表示大于

-type:查找某一类文件,b-块设备文件  d-目录  c-字符设备  p-管道文件  l-符号链接文件  f-普通文件

-follow:如果遇到符号链接文件,就跟踪到所指文件的路径下

示例:

1.查找普通文件,查询目录

[root@tsgz7 /]# find /opt/rh -type f
/opt/rh/123/1.txt
/opt/rh/123/2.txt
/opt/rh/123/3.txt

[root@tsgz7 /]# find /opt/rh -type d
/opt/rh
/opt/rh/123
2.查找一天之内访问过的普通文件
[root@tsgz7 /]# find /opt/rh -atime -1 -type f
/opt/rh/123/1.txt
/opt/rh/123/2.txt
/opt/rh/123/3.txt

3.查看当前路径下所有文件的信息

[root@tsgz7 123]# find ./ -type f -exec file {} ;  大括号表示之前查找出来的文件名
./1.txt: ASCII text
./2.txt: empty
./3.txt: empty
./4.txt: empty
[root@tsgz7 123]# cat 2.txt
[root@tsgz7 123]# cat 1.txt
123123 2.txt 3.txt 4.txt

4.查找当前文件夹下所有文件并显示详细信息

[root@tsgz7 123]# find . -type f |xargs ls -l
-rw-r--r--. 1 root root 25 2月  18 20:36 ./1.txt
-rw-r--r--. 1 root root  0 2月  18 20:36 ./2.txt
-rw-r--r--. 1 root root  0 2月  18 20:36 ./3.txt
-rw-r--r--. 1 root root  0 2月  18 20:36 ./4.txt

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~华丽的切割线~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

原文地址:https://www.cnblogs.com/hollyhock/p/10397869.html