欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

linux下删除文件多个文件问题 LINUX下查找几天之前的文件并删除的方法 自己亲自做的 有大用 有大大用 有大大大用

shiping1 的头像

以下是自己亲自做的 有大用

1)查先看看这个目录下 7天前的文件有哪些
find /home/wwwroot/www_aaaa_com/public_html/php/baoming/  -mtime +7 -name "*.txt" -exec ls -l {} \;.sh
2)再删除这个目录下7天前的文件

find /home/wwwroot/www_aaaa_com/public_html/php/baoming/  -mtime +7 -name "*.txt" -exec rm -rf {} \;

以上试了是正确的
3)写一下 clear.sh文件吧 目的是删除这个目录下7天前的文件
find /home/wwwroot/www_aaaa_com/public_html/wap/baoming/  -mtime +7 -name "*.txt" -exec rm -rf {} \;
find /home/wwwroot/www_bbbb_com/public_html/wap/baoming/  -mtime +7 -name "*.txt" -exec rm -rf {} \;
find /home/wwwroot/www_dddd_com/public_html/php/baoming/  -mtime +7 -name "*.txt" -exec rm -rf {} \;
find /home/wwwroot/www_eeee_com/public_html/php/baoming/  -mtime +7 -name "*.txt" -exec rm -rf {} \;
find /home/wwwroot/www_ffff_com/public_html/php/baoming/  -mtime +7 -name "*.txt" -exec rm -rf {} \;
find /home/wwwroot/www_gggg_com/public_html/php/baoming/  -mtime +7 -name "*.txt" -exec rm -rf {} \;
find /home/wwwroot/www_hhhh_com/public_html/php/baoming/  -mtime +7 -name "*.txt" -exec rm -rf {} \;
find /home/wwwroot/www_iiii_com/public_html/php/baoming/  -mtime +7 -name "*.txt" -exec rm -rf {} \;
find /home/wwwroot/www_jjjj_com/public_html/php/baoming/  -mtime +7 -name "*.txt" -exec rm -rf {} \;
find /home/wwwroot/www_kkkk_com/public_html/php/baoming/  -mtime +7 -name "*.txt" -exec rm -rf {} \;
find /home/wwwroot/www_llll_com/public_html/php/baoming/  -mtime +7 -name "*.txt" -exec rm -rf {} \;
find /home/wwwroot/www_mmmm_com/public_html/php/baoming/  -mtime +7 -name "*.txt" -exec rm -rf {} \;
find /home/wwwroot/www_nnnn_com/public_html/php/baoming/  -mtime +7 -name "*.txt" -exec rm -rf {} \;
find /home/wwwroot/www_oooo_com/public_html/php/baoming/  -mtime +7 -name "*.txt" -exec rm -rf {} \;
find /home/wwwroot/www_pppp_com/public_html/php/baoming/  -mtime +7 -name "*.txt" -exec rm -rf {} \;
find /home/wwwroot/www_qqqq_com/public_html/php/baoming/  -mtime +7 -name "*.txt" -exec rm -rf {} \;
find /home/wwwroot/www_rrrr_com/public_html/php/baoming/  -mtime +7 -name "*.txt" -exec rm -rf {} \;
find /home/wwwroot/www_ssss_com/public_html/php/baoming/  -mtime +7 -name "*.txt" -exec rm -rf {} \;
find /home/wwwroot/www_tttt_com/public_html/php/baoming/  -mtime +7 -name "*.txt" -exec rm -rf {} \;
find /home/wwwroot/www_uuuu_com/public_html/php/baoming/  -mtime +7 -name "*.txt" -exec rm -rf {} \;
find /home/wwwroot/www_vvvv_com/public_html/php/baoming/  -mtime +7 -name "*.txt" -exec rm -rf {} \;
find /home/wwwroot/www_wwww_com/public_html/php/baoming/  -mtime +7 -name "*.txt" -exec rm -rf {} \;
find /home/wwwroot/www_xxxx_com/public_html/php/baoming/  -mtime +7 -name "*.txt" -exec rm -rf {} \;
find /home/wwwroot/www_yyyy_com/public_html/php/baoming/  -mtime +7 -name "*.txt" -exec rm -rf {} \;
find /home/wwwroot/www_zzzz_com/public_html/php/baoming/  -mtime +7 -name "*.txt" -exec rm -rf {} \;
find /home/wwwroot/www_1111_com/public_html/php/baoming/  -mtime +7 -name "*.txt" -exec rm -rf {} \;
find /home/wwwroot/www_2222_com/public_html/php/baoming/  -mtime +7 -name "*.txt" -exec rm -rf {} \;
find /home/wwwroot/www_3333_com/public_html/php/baoming/  -mtime +7 -name "*.txt" -exec rm -rf {} \;
find /home/wwwroot/www_4444_com/public_html/php/baoming/  -mtime +7 -name "*.txt" -exec rm -rf {} \;
find /home/wwwroot/www_5555_com/public_html/php/baoming/  -mtime +7 -name "*.txt" -exec rm -rf {} \;
这样就删除了这些目录下的txt文件








linux下删除文件多个文件问题


rm -rf *.*  删除这个目录下所有的文件
rm -rf *关键字*  删除和关键字有关的所有文件

可以直接写脚本,每天定时删除:
例如:(删除/data/bak目录下以20开头,后缀为*.jar.gz,更改时间距现在5天以前的所有文件,也就是说只保留最近5天的备份文件)
find /data/bak -name "20*.jar.gz" -type f -mtime +5 -exec rm {} \; > /dev/null 2>&1

/data/bak 备份目录(改成你自己的)
2010*_bak.gz 文件名及类型 (改成你自己的,注意*)
-type f    表示查找普通类型的文件,f表示普通文件。
-mtime +5   按照文件的更改时间来查找文件,+5表示文件更改时间距现在5天以前;如果是 。
-exec rm {} \;   表示执行rm命令,exec选项后面跟随着所要执行的命令或脚本,然后是一对儿{ },一个空格和一个\,最后是一个分号。
/dev/null 2>&1  把标准出错重定向到标准输出,然后扔到/DEV/NULL下面去。通俗的说,就是把所有标准输出和标准出错都扔到垃圾桶里面;其中的& 表示让该命令在后台执行。

来自 http://zhidao.baidu.com/link?url=qnSU1T7ejv0KrGY6LIPGpnR5TKUWbBCiswGreYQupdwyJXDgp5xtE7-saIWEHjLSKlGXfuA-MoheoKf-uhu5jK

我做的是在 118.123的/root/crontabdirectory  目录下
clear.sh


 
普通分类: