码迷,mamicode.com
首页 > 系统相关 > 详细

linux 命令总结

时间:2016-12-11 01:37:07      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:查找   ida   参数   mtime   access   bsp   目录   创建   删除   

①用find命令查找并删除文件

用脚本创建测试数据:

[root@greymouster ceshidata]# for n in `seq 10`
> do
> date -s "12/0$n/16"
> touch access_www_`(date +%F)`.log
> done

[root@greymouster ceshidata]# ll
总用量 0
-rw-r--r-- 1 root root 0 12月 1 00:00 access_www_2016-12-01.log
-rw-r--r-- 1 root root 0 12月 2 00:00 access_www_2016-12-02.log
-rw-r--r-- 1 root root 0 12月 3 00:00 access_www_2016-12-03.log
-rw-r--r-- 1 root root 0 12月 4 00:00 access_www_2016-12-04.log
-rw-r--r-- 1 root root 0 12月 5 00:00 access_www_2016-12-05.log
-rw-r--r-- 1 root root 0 12月 6 00:00 access_www_2016-12-06.log
-rw-r--r-- 1 root root 0 12月 7 00:00 access_www_2016-12-07.log
-rw-r--r-- 1 root root 0 12月 8 00:00 access_www_2016-12-08.log
-rw-r--r-- 1 root root 0 12月 9 00:00 access_www_2016-12-09.log
-rw-r--r-- 1 root root 0 12月 10 00:00 access_www_2016-12-10.log

删除3天以前的.log

[root@greymouster ceshidata]# find ./ -type f -name "*.log" -mtime +3 |xargs rm -f
[root@greymouster ceshidata]# ll
总用量 0
-rw-r--r-- 1 root root 0 12月 7 00:00 access_www_2016-12-07.log
-rw-r--r-- 1 root root 0 12月 8 00:00 access_www_2016-12-08.log
-rw-r--r-- 1 root root 0 12月 9 00:00 access_www_2016-12-09.log
-rw-r--r-- 1 root root 0 12月 10 00:00 access_www_2016-12-10.log

用 -exec 参数删除

[root@greymouster ceshidata]# find ./ -type f -name "*.log" -mtime +3 -exec rm -f {} \;
[root@greymouster ceshidata]# ll
总用量 0
-rw-r--r-- 1 root root 0 12月 7 00:00 access_www_2016-12-07.log
-rw-r--r-- 1 root root 0 12月 8 00:00 access_www_2016-12-08.log
-rw-r--r-- 1 root root 0 12月 9 00:00 access_www_2016-12-09.log
-rw-r--r-- 1 root root 0 12月 10 00:00 access_www_2016-12-10.log

[root@greymouster ceshidata]# find ./ -type f -name "*.log" -mtime +1 -delete  也可以删除 

 ②过滤出所有的一级目录

[root@greymouster chenchen]# ls -l |grep ^d   或^dr

linux 命令总结

标签:查找   ida   参数   mtime   access   bsp   目录   创建   删除   

原文地址:http://www.cnblogs.com/chenchenphp/p/6158493.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!