如何在gzip压缩在bash的所有子目录中的所有文件 [英] How to gzip all files in all sub-directories in bash
问题描述
我希望我的当前位置的子目录中遍历和单独gzip压缩每个文件。对于目录中的文件压缩和解,我用
I want to iterate among sub directories of my current location and gzip each file seperately. For zipping files in a directory, I use
for file in *; do gzip "$file"; done
但可以在当前目录下,而不是当前目录的子目录只是工作。我怎样才能把上面的语句,以便它也呼啸而过的所有子目录中的文件?
but this can just work on current directory and not the sub directories of the current directory. How can I rewrite the above statements so that It also zips the files in all subdirectories?
推荐答案
无需循环或任何超过找到
和的gzip
:
No need for loops or anything more than find
and gzip
:
find . -type f ! -name '*.gz' -exec gzip "{}" \;
这在查找和当前目录中名称不与。广州
扩展名结尾(即,是不是已经全部文件COM $下的所有常规文件p $ pssed)。它调用的gzip
上的每个文件。
This finds all regular files in and below the current directory whose names don't end with the .gz
extension (that is, all files that are not already compressed). It invokes gzip
on each file individually.
编辑的基础上,从注释用户未知
:
Edit, based on comment from user unknown
:
花括号( {}
)被替换为文件名,这是直接传递,作为一个单一的一句话,下面的命令 - EXEC
,你可以在这里看到:
The curly braces ({}
) are replaced with the filename, which is passed directly, as a single word, to the command following -exec
as you can see here:
$ touch foo
$ touch "bar baz"
$ touch xyzzy
$ find . -exec echo {} \;
./foo
./bar baz
./xyzzy
这篇关于如何在gzip压缩在bash的所有子目录中的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!