简体   繁体   中英

Is there a way to add or update file in tar.gz(tgz) without decompress?

I'm looking for a way to update tgz file. I know what I can update tgz file by unzipping it, inserting file in directory and re-compressing it. But I do not want decompressed file was created in my disc.

Tar has 'r' option(--append) what appending files to the end of an archive but when I use tar with 'r' option, console logged 'cannot update compressed archive.', 'Error is not recoverable: exiting now.'

If it is impossible, I cannot help but if there is a way, plz let me know.

I modified my question according to Basile Starynkevitch's comment.

This is command for testing.

tar -rf myComppressedFile.tgz insert.txt

Result

tar: Cannot update compressed archives
tar: Error is not recoverable: exiting now

vim myCompressedFile.tgz

./file1.txt
./file2.txt
./file3.txt
./directory1/
./directory1/file4.txt

what I want to update

./file1.txt
./file2.txt
./file3.txt
./directory1/
./directory1/file4.txt
./insert.txt <<<< I want to add like this file

My tgz file is about more 100 megabytes.

Is there a way to add or update file in tar.gz(tgz) without decompress?

No, there is no way.

Since compression by gzip happens on the entire tar archive (after making the tar ball). Observe the runtime behavior of your tar command using strace(1) (so read syscalls(2) ) or ltrace(1)

Read documentation of tar(1) . Study the source code of GNU tar (it is free software ).

On my Debian/Sid/x86-64, the libc6-dev package provides the /usr/include/tar.h header. I invite you to look inside that header file, it describes the format of tar balls.

Consider using other approaches: some sqlite database, using postgresql or mongodb or GDBM , some afio archive (where each file is perhaps compressed before archiving it). See also the tardy utility.

I'm looking for a way to update tgz file

Why?

Did you consider instead using version control on the underlying files before their archival with tar ? Something like git ?

But I do not want decompressed file was created in my disk.

Why?

The decompressed file might be a temporary one....

Of course, you would need to have different approaches if you deal with a few megabytes of data or if you have a few petabytes of data. Of course, if you are developing a critical embedded application (eg medical devices, interpl.netary satellite software, DO-178C software systems), things could be different.

There are lots of trade-offs to consider (including money and development time and economical impact of loss of data or of corrupted archive and legal regulations regarding the archive and its data integrity: in a flight recorder you should ensure the data is readable after the crash of an aircraft).

My tgz file is about more 100 megabytes.

This is tiny , and practically would fit (for most Linux systems in 2020, even a cheap RaspBerryPi ) in the page cache . You might use some file system kept in RAM (eg tmpfs )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM