I need to compress and decompress each of the files of a particular type say *.html
in their respective location.
For decompression, I used following command, it seemed to work for me:
find dir -name "*.html.tar.gz" -exec tar -xvzf {} \;
I'm able to see *.htmp.tar.gz
in their respective directories.
For compression, I'm trying following command but it is not working as concatenation is not happening to the argument from find:
find dir -name "*.html" -exec tar -cvzf {}.tar.gz {} \;
Please suggest solution to this and let me know if solution to the decompression is not foolproof.
EDIT: Although I've right now used gunzip
which do not require target name, but I'm wondering if tar
is not possible at all. So, waiting for answer which solves the original problem.
EDIT: the requirement is to have a single command because I need to run it through fork()
and exec()
command from C function. So, I think piping is not possible.
EDIT: Also I'm looking for efficient way, because I want as little overhead as possible to the time taken for compression.
gzip
will preserve ownership and file attributes if possible. If runninggzip
as the user that own the directories and files, or asroot
, then this is possible.