暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

linux之find命令汇总

齐浩的运维笔记 2019-02-25
224



Linuxfind命令用法汇总

一、按名称查找文件的基本命令

1.当前目录查找

[kaiko@localhost ]$ findtest.txt

test.txt

 

2.主目录查找

查找 /etc目录下,名称为passwd的文件

[kaiko@localhost ]$find/etc -name passwd

/etc/passwd

 

3.忽略大小写,查找文件

[kaiko@localhost ]$find/etc -iname passwd

/etc/passwd

/etc/PASSWD

 

4.按照文件类型查找

[kaiko@localhost ]$find /tmp -type f

/tmp/yum_save_tx.2019-02-13.10-19.nvg7jf.yumtx

/tmp/yum_save_tx.2019-02-18.a12-22.7UYz7W.yumtx

/tmp/yum_save_tx.2019-02-12.14-32.RxA0RZ.yumtx

/tmp/.X0-lock

/tmp/sh-thd-1550244207

/tmp/lua_epBbay

 

二、按照权限查找文件

1.查找权限为777的所有文件

[kaiko@localhost ]$ find/tmp  -type  f  -perm 777

/tmp/test

/tmp/passwd.txt

 

[kaiko@localhost ]$ls -l /tmp

-rwxrwxrwx. 1 root root  0 2月  22 14:36 passwd.txt

-rwxrwxrwx. 1 root root 40 2月  18 22:46 test

 

2.查找权限不为777的所有文件

[kaiko@localhost ]$find /tmp-type f!-perm 777

 

3.查找SGID文件

[kaiko@localhost ]$find/-perm/g+s

 

 

4.查找SUID文件

[kaiko@localhost ]$find/-perm/u+s

 

5.查找只读文件

[kaiko@localhost ]$find / -perm /u+r

 

6.查找可执行文件

[kaiko@localhost ]$find /-perm/a+x

 

7.找到权限为777的目录并修改为755

[kaiko@localhost ]$find  /-perm777 -exec  chmod  755  {}  \;

 

8.查找并删某个文件

删除以test开头的文件

[kaiko@localhost ]$find/var/log  -type  f  -name “test.*” -exec rm -rf  {}  \;

 

 

9.同时删除包含俩个参数文件

删除文件中以2018开头和以 .log 结尾的文件

[kaiko@localhost ]$

find  /var/log  -type f -name “2018*”-o  -name “*.log”| xargs rm -rf

 

10.查找指定路径下的所有空目录归档

[kaiko@localhost ]$ find/  -type  d  -empty

 

11.查找指定路径下的所有空文件

[kaiko@localhost ]$find  /tmp  -type  f   -empty

 

三、按照所有者和组的查询文件

1.查找所有者为student 名称为test.txt的文件

[kaiko@localhost ]$find  /   -user student  -name test.txt

 

2.查找基于用户的所有文件 

[kaiko@localhost ]$find  ~   -user  kaiko

 

3.查找基于组的所有文件

[kaiko@localhost ]$ find  /home  -group  student

 

4.查找~目录下用户student的所有以.txt结尾的文件

[kaiko@localhost ]$find~ -user  student -name “.txt”

 

 

 

四、按照日期和时间查找文件和目录

1.查找最近30天访问的文件

[kaiko@localhost ]$find  /   -atime  30

 

 

2.查找30天—100天之间修改的文件

[kaiko@localhost ]$find  /  -mtime  +50   -mtime   -100

 

3.查找过去1小时修改的文件

[kaiko@localhost ]$find/-cmin-60

 

4.查找最近1小时修改的文件

[kaiko@localhost ]$find/-mmin-60

 

5.查找最近1小时访问的文件

[kaiko@localhost ]$find/-amin-60

 

 

五、根据大小查找文件和目录

1.查询50M的文件

[kaiko@localhost ]$find / -size50M

 

2.查询大小在20M~100M之间的文件

[kaiko@localhost ]$find/ -size  +20M -size  -100M

 

3.查询大小为100M的文件并删除

[kaiko@localhost ]$find  /  -size  100M  -exec  rm -rf {}  \;

 

 


文章转载自齐浩的运维笔记,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论