find Linux命令

2019-10-22  本文已影响0人  清闲的云云子

格式:

find path option file

path:查找的目录路径

option:按什么进行查找

file: 查找的文件特征

(如果查不到,就将文件名加""试试)

find -name april*                在当前目录下查找以april开始的文件

find -name april* > a.txt        在当前目录下查找以april开始的文件,并把结果输出到a.txt中

find -name ap* -o -name may*     查找以ap或may开头的文件

find /tmp -name wa* -type l      在/tmp下查找名为wa开头且类型为符号链接的文件

find /home -mtime -2             在/home下查最近两天内改动过的文件

find /home -atime -1             查/home下1天之内被存取过的文件

find /home -mmin +60             在/home下查60分钟前改动过的文件

find /home -amin +30             在/home下查最近30分钟前被存取过的文件

find /home -newer tmp.txt        在/home下查更新时间比tmp.txt近的文件或目录

find /home -anewer tmp.txt       在/home下查存取时间比tmp.txt近的文件或目录

find /home -used -2              列出/home中文件或目录被改动过之后,在2日内被存取过的文件或目录

find /home -user cnscn           列出/home目录内属于用户cnscn的文件或目录

find /home -uid +501             列出/home目录内用户的识别码大于501的文件或目录

find /home -group cnscn          列出/home内组为cnscn的文件或目录

find /home -gid 501              列出/home内组id为501的文件或目录

find /home -nouser               列出/home内不属于本地用户的文件或目录

find /home -nogroup              列出/home内不属于本地组的文件或目录

find /home -maxdepth 4 -name tmp.txt   列出/home内的tmp.txt 查时深度最多为3层

find /home -mindepth 3 -maxdepth 5 -name tmp.txt   在/home的第二层到第四层之间查tmp.txt

find /home -empty                查找/home中大小为0的文件或空目录

find /home -size +512k           查/home中大于512k的文件

find /home -size -512k           查/home中小于512k的文件

find /home -links +2             查/home中硬连接数大于2的文件或目录

find /home -perm 0700            查/home中权限为700的文件或目录

find -type f -exec ls -l {} \;   查当前目录下的所有普通文件,并在-exec选项中使用ls -l命令将它们列出

find -name a.txt -ok rm {} \;     查当前目录下的a.txt并询问是否删除

把当前目录下的file移动到/test下:

find -type f -exec mv {} /test \;

删除指定时间之前的文件:

find -type f -name *.log -mtime +180 -exec rm {} \;

在/logs目录中查找更改时间在7日以前的文件并删除它们:

$ find logs/ -type f -mtime +7 -exec rm -f {} \;

在/logs目录中查找更改时间在7日以内的文件并删除它们:

$ find logs/ -type f -mtime -7 -exec rm -f {} \;

然后加入的计划任务中每日执行便可

上一篇 下一篇

猜你喜欢

热点阅读