linux命令find:删除一天前的文件,按文件大小、权限、所属用户查询等

linux中,常用的find命令:

1:查询当前所有的.txt文件

[root@localhost ~]# find ./ -name "*.txt"
./.cache/tracker/db-version.txt
./.cache/tracker/db-locale.txt
./.cache/tracker/miner-applications-locale.txt
./.cache/tracker/last-crawl.txt
./.cache/tracker/first-index.txt
./1/2.txt
./1/1.txt
./1.txt

2:删除一天以内修改过的文件(和删除一天前的文件类似)

[root@localhost 1]# touch 10.txt
[root@localhost 1]# 
[root@localhost 1]# ls
10.txt  1.txt  2.txt  nginx-1.12.2  wenjian
[root@localhost 1]# find ./ -mtime -1 
./
./10.txt
[root@localhost 1]# find ./ -mtime -1 -exec rm -rf {} \;
rm: refusing to remove "." or ".." directory: skipping "./"
[root@localhost 1]# ls
1.txt  2.txt  nginx-1.12.2  wenjian

find ./ -mtime -1 是指一天内;当然 +10就是十天之前,而10就是第十天创建的文件或者目录文件

-exec +命令 {} \;固定写法

"{}"表示前面的内容,也就是“find ./ -mtime -1”得到的内容,

例如:

将本文件下的.txt文件拷贝到/root/find/文件下面
[root@localhost 1]# find ./ -name "*.txt" -exec cp {} /root/find/ \;
[root@localhost 1]# ls /root/find/
1.txt  2.txt

3:查询多个类型的文件

-a and 并且      -o or 或者
+ 超过           - 低于
查询本文件下所有的.pdf和.sh文件
[root@localhost 1]# find ./ -name "*.pdf" -o -name "*.sh"
./1.pdf
./2.sh
查询/etc文件下大于30k并且小于40k的文件
[root@localhost 1]# find /etc/ -size +30k -a -size -40k| wc -l
4

4:权限查询

查询本文件下权限是777的文件
[root@localhost 1]# find ./ -perm 777
./1
查询本文件不低于644权限的文件
[root@localhost 1]# find ./ -perm -644
...

5:查询层序

查询第一层的文件
[root@localhost 1]# find /bin/ -maxdepth 1 -perm 777
/bin/gtbl
/bin/bashbug
/bin/gtar
/bin/sh
/bin/bunzip2
...

6:查询所属用户

查询属于ad用户的文件
[root@localhost 1]# find / -user ad

 

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值