Gzip multiple files individually and keep the original files

后端 未结 4 821
自闭症患者
自闭症患者 2021-02-02 17:47

I am looking to gzip multiple files (into multiple .gz files) in a directory while keeping the originals.

I can do individual files using these commands:



        
4条回答
  •  暖寄归人
    2021-02-02 18:32

    I'd use bash(1)'s simple for construct for this:

    for f in *cache.html ; do gzip -c "$f" > "$f.gz" ; done
    

    If I knew the filenames were 'sane', I'd leave off the "" around the arguments, because I'm lazy. And my filenames are usually sane. But scripts don't have that luxury.

提交回复
热议问题