免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
123下一页
最近访问板块 发新帖
查看: 10433 | 回复: 21
打印 上一主题 下一主题

我在一个目录下,find+gzip时,为啥总会报:already has .gz suffix -- unchanged [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-01-10 10:38 |只看该作者 |倒序浏览
本帖最后由 welcome008 于 2011-01-10 10:40 编辑

find . -name 'le.*' -mtime +1 -type f -exec gzip {} \;

gzip: ./le.20110107220830.gz already has .gz suffix -- unchanged


当然,我确定在执行之前,该目录下的文件都是没有压缩的。

论坛徽章:
0
2 [报告]
发表于 2011-01-10 10:40 |只看该作者
哦,难道说

find+gzip后生成的gz文件,又被find了,然后继续gzip,这样就报错?

论坛徽章:
0
3 [报告]
发表于 2011-01-10 10:44 |只看该作者
回复 2# welcome008


    你是想每个文件对应一个包还是把所有的打成一个包

论坛徽章:
23
15-16赛季CBA联赛之吉林
日期:2017-12-21 16:39:27白羊座
日期:2014-10-27 11:14:37申猴
日期:2014-10-23 08:36:23金牛座
日期:2014-09-30 08:26:49午马
日期:2014-09-29 09:40:16射手座
日期:2014-11-25 08:56:112015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:49:0315-16赛季CBA联赛之山东
日期:2017-12-21 16:39:1915-16赛季CBA联赛之广东
日期:2016-01-19 13:33:372015亚冠之山东鲁能
日期:2015-10-13 09:39:062015亚冠之西悉尼流浪者
日期:2015-09-21 08:27:57
4 [报告]
发表于 2011-01-10 10:47 |只看该作者
这样试试:
find . -depth -name 'le.*' -mtime +1 -type f -exec gzip {} \;

论坛徽章:
3
2015年迎新春徽章
日期:2015-03-04 09:56:11数据库技术版块每日发帖之星
日期:2016-08-03 06:20:00数据库技术版块每日发帖之星
日期:2016-08-04 06:20:00
5 [报告]
发表于 2011-01-10 10:58 |只看该作者
find . -name 'le.*' -mtime +1 -type f -exec gzip {} \;

gzip: ./le.20110107220830.gz already has . ...
welcome008 发表于 2011-01-10 10:38



    你trace一下就看出来了啊,当然,如果你熟悉UNIX下的C语言编程的话

论坛徽章:
0
6 [报告]
发表于 2011-01-10 11:02 |只看该作者
这样试试:
find . -depth -name 'le.*' -mtime +1 -type f -exec gzip {} \;
ly5066113 发表于 2011-01-10 10:47



    我当前目录下没有子目录啊

另,tim把depth的作用说说,貌似不只是对子目录有用的,好像对要查找的目录本身也起作用,如果做删除,甚至可以对要查找的目录本身删除:


mkdir -p testdir/{a,b,c/d}
find testdir  -exec rmdir  {} \;
mkdir -p testdir/{a,b,c/d}
find testdir -depth -exec rmdir  {} \;

论坛徽章:
0
7 [报告]
发表于 2011-01-10 11:06 |只看该作者
本帖最后由 xiaopan3322 于 2011-01-10 11:09 编辑

回复 6# welcome008

-depth
    Process each directory's contents before the directory itself.

-maxdepth levels
    Descend at most levels (a non-negative integer) levels of directories below the command line arguments. `-maxdepth 0' means only apply the tests and actions to the command line arguments.

-mindepth levels
    Do not apply any tests or actions at levels less than levels (a non-negative integer). `-mindepth 1' means process all files except the command line arguments.

论坛徽章:
0
8 [报告]
发表于 2011-01-10 11:14 |只看该作者
回复  welcome008

-depth
    Process each directory's contents before the directory itself.

...
xiaopan3322 发表于 2011-01-10 11:06



    貌似不仅仅这样

论坛徽章:
23
15-16赛季CBA联赛之吉林
日期:2017-12-21 16:39:27白羊座
日期:2014-10-27 11:14:37申猴
日期:2014-10-23 08:36:23金牛座
日期:2014-09-30 08:26:49午马
日期:2014-09-29 09:40:16射手座
日期:2014-11-25 08:56:112015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:49:0315-16赛季CBA联赛之山东
日期:2017-12-21 16:39:1915-16赛季CBA联赛之广东
日期:2016-01-19 13:33:372015亚冠之山东鲁能
日期:2015-10-13 09:39:062015亚冠之西悉尼流浪者
日期:2015-09-21 08:27:57
9 [报告]
发表于 2011-01-10 11:16 |只看该作者
回复 6# welcome008


就是“深度优先”算法,find默认是“广度优先”的。
对删除很有用,对于你的情况不知道有没有用。

论坛徽章:
0
10 [报告]
发表于 2011-01-10 11:20 |只看该作者
貌似不仅仅这样
welcome008 发表于 2011-01-10 11:14



    看下这篇文章:
http://content.hccfl.edu/pollock/unix/findcmd.htm

When using find to locate files for backups, it often pays to use the "-depth" option (really a criterion that is always true), which forces the output to be depth-first—that is, files first and then the directories containing them.  This helps when the directories have restrictive permissions, and restoring the directory first could prevent the files from restoring at all (and would change the time stamp on the directory in any case).  Normally, find returns the directory first, before any of the files in that directory.  This is useful when using the "-prune" action to prevent find from examining any files you want to ignore:

find / -name /dev -prune | xargs tar ...
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP