我正在写一个脚本,我正在抓取文件。
我可能会压缩文件,创建一个同名的文件,并尝试gzip这个,例如
$ ls -l archive/
total 4
-rw-r--r-- 1 xyzzy xyzzy  0 Apr 16 11:29 foo
-rw-r--r-- 1 xyzzy xyzzy 24 Apr 16 11:29 foo.gz
$ gzip archive/foo
gzip: archive/foo.gz already exists; do you wish to overwrite (y or n)? n   
    not overwritten
通过使用gzip --force,我可以强制gzip覆盖foo.gz,但在这种情况下,我认为如果我覆盖,我很可能会丢失数据foo.gz。似乎没有命令行开关强制gzip .gz单独保留文件...在提示符下按'n'的非交互式版本。
我尝试过,gzip --noforce并gzip --no-force希望这些可能遵循GNU选项标准,但这些都不起作用。
这有直接的解决方法吗?
编辑:
事实证明,这是阅读信息页而不是手册页所花费的时间之一。
从信息页面:
`--force'
`-f'
     Force compression or decompression even if the file has multiple
     links or the corresponding file already exists, or if the
     compressed data is read from or written to a terminal.  If the
     input data is not in a format recognized by `gzip', and if the
     option `--stdout' is also given, copy the input data without
     change to the standard output: let `zcat' behave as `cat'.  If
     `-f' is not given, and when not running in the background, `gzip'
     prompts to verify whether an existing file should be overwritten.
手册页缺少文本,不在后台运行时
在后台运行时,gzip不会提示,除非-f调用该选项,否则不会覆盖。
                  @BillMcGonigle你的评论应该是答案!
                
                
                  
                    —
                    Rockallite 
                    
                  
                
              
find ./ ! -name "*gz" -exec gzip {} \; &这工作:find ./ ! -name "*gz" -print0 | xargs -0 -n 1 -t gzipgzip报告:gzip: ./2012-July.txt.gz already exists; not overwritten