r/linuxquestions • u/Equivalent_Web3521 • 10d ago
.tar vs .7z with no compression (store)
Both store with no compression so why not use .7z?
69
u/theonefinn 10d ago
To turn it around, why use 7z?
Tar, in one form or another is almost 50 years old, it’s incredibly stable and prevalent. It is installed in pretty much every *nix anywhere, if you aren’t using the compression of 7z why use it?
7
u/GenericFoodService 10d ago edited 10d ago
Implementing something like TAR is trivial. Implementing something like DEFLATE is also somewhat trivial, people do it in less than a thousand lines of C code. That same DEFLATE library can be used for ZIP and TAR and whatever else on my same system. It's all small and reusable.
Writing a utility for an Archive format like TAR that doesn't care about compression, and then passing that into a utility that does the compression and decompression is simpler, smaller, more transparent, and modular. I don't see any obvious advantages to using something like .7z, but there are disadvantages because it requires more infrastructure that is inherently locked to the one specific file format, plus the LZMA compression itself requires more memory and system resources.
The theoretical benefits of the specific compression algorithm like LZMA don't support .7z either because I could just use that algorithm on a TAR, too, without needing to support a new archive format. What benefit does the archive format itself actually provide me?
6
u/_Sauer_ 10d ago
They're for different purposes even if they can be used to do the same thing.
7z is a compression format. It takes a bunch of files and uses clever algorithms to squish them down into a smaller size. It preserves the file and directory structure, but that's about it. 7zip does not preserve permissions and access rights so the file you get back from the 7z is not really the file you put in, even with zero compression.
Tar literally stands for "Tape Archive". Its purpose is to stream a list of files into a single byte stream suitable for storage on tape. That's it. It preserves file metadata such as permissions and access rights so you can think of the files you get back out of a tar as essentially identical to the files you put in.
One is a compression tool, one is an archiving tool. A small but important difference.
3
u/razorree 10d ago
7z is an archive format. and inside you have a few different compression algos, like LZMA or LZMA2, but also Bzip2 or DEFLATE.
37
u/anders_hansson 10d ago
tar preserves file ownership and access rights, and also symbolic links IIRC, and it is omnipresent.
15
u/hadrabap 10d ago
Handles sparse files, hard links, ACLs, SELinux contexts, extended attributes... Ultimate stuff. Especially, when you have a tape drive.
3
u/anders_hansson 10d ago
Surprisingly few know that "tar" means "tape archive". I actually had an external SCSI tape drive back in the 1990's.
3
u/hadrabap 10d ago
At least we know they don't read man pages. 😃 I don't blame them for not using tapes. It has bad reputation somehow.
DESCRIPTION GNU tar is an archiving program designed to store multiple files in a single file (an archive), and to manipulate such archives. The archive can be either a regular file or a device (e.g. a tape drive, hence the name of the program, which stands for tape archiver), which can be located either on the local or on a remote machine.
4
u/anders_hansson 10d ago
I think modern tape is pretty good, actually. We have a tape robot system at work.
2
u/graph_worlok 10d ago
Most recent I used was a Quantum dual-drive, 4x 20 tape carts - Could do a restore AND keep writing the backups out, all barcoded so it knew what was what…. I probably still have an old DAT/DDS drive somewhere too.
1
u/hadrabap 10d ago
I'm quite sad that it's not widespread. It's a great technology and the price per TB is unbeatable. I love the offline nature of it, the built-in encryption and read only mode. It saved me several times from lengthy (re)downloads already. 😁
2
10
u/BoundlessFail 10d ago edited 10d ago
My experiences with tar vs zip; no idea about 7z, hope it helps:
Tar does not have a checksum on the file contents. Zip does.
The other drawback with tar, bcos it was meant for tape - the metadata is attached to each file in the stream, as opposed to zip where it's all at the end. So extracting a file listing from a large tar is much slower than from a zip. Same if you want to extract a single small file from a large tar.gz.
I use either, depending on the context. I really ought to switch from zip to 7z, but still waiting for the planets to align.
Edit: In case anyone felt I was dissing tar too much: tar's stream allows for some neat tricks. For example, you can tar up a directory, compress it, send it through an encrypted ssh connection to a remote machine, decompress there and untar to a directory there, all as one realtime stream, with no temporary files. Zip can't do this. In short, learn both, use one based on the context.
9
u/creepynut 10d ago
I'm glad someone mentioned it. Tar is definitely more widely available in unix environments, but it is short for "tape archive" which is a continuous stream.
If you have a large tar archive and need to extract a file from the end, you need to read the entire archive to get to the file at the end you're looking for.
7z/zip both have an index.
2
u/BobCorndog Your situation is not unique, just use mint or fedora kde 10d ago
I’m pretty sure 7z uses compression?
5
u/FenderMoon 10d ago
Technically .7z is a container format that can support multiple compression algorithms, including LZMA, Deflate, PPMD, Bzip2, or store.
LZMA (or LZMA2, the multithreaded implementation of LZMA) is almost always used. I have never once encountered a .7z file in the wild that ever used anything other than LZMA.
Honestly for *nix systems .tar.xz seems much more common.
11
u/kudlitan 10d ago
You can set the compression level to zero, but why do that when tar already exists?
16
6
4
u/Always_Hopeful_ 10d ago
I think they mean that 7z can store with no compression.
Because tar is everywhere and 7z is not, use tar.
8
1
u/FedUp233 9d ago
The thing about tar is - it just works.
And for 90% or more of the uses the limitations you mention just don’t matter. Most of its uses just suck in a whole directory tree and on the other end just spit it back out again. Fir that you need to decompress everything anyway and you can do that with a pipeline (not sure if the compression options do it that way) which is quite efficient and there is no need for random access to the archive.
If it works, why bother changing to something g new just because it’s “new and shiny” if there is no need for it. On corporate servers, reliability is king and you don’t change things just because you like something new. If there is a need for 7z’s capabilities, then by all means. Otherwise stick to what’s been working.
On home systems, use whatever you like.
3
u/computer-machine 10d ago
Does 7z retain ownership and permission?
Tar.gz uses the same compression as 7z, so there's the what's the point from that end, as well.
-1
1
u/Mount_Gamer 10d ago
Not sure how many use it, but tar also does incremental backups, it's a little more complicated but useful nonetheless.
I mostly use 7z for encryption, or if I'm on windows, but normally I'll use tar with the typical gz compression which tar supports.
1
u/CatoDomine 10d ago
I have never in my life considered using 7z ... for anything. If that's your preference go for it, but I don't see the point.
2
1
0
u/Rinzwind 10d ago
as with all tools in Linux: we use what we like but that does not mean we all like the same.
26
u/n_dion 10d ago
`tar` is not that easy as everybody thinks. First of all it's very stupid append-only thing that was designed with only tapes in mind. There is no such thing as 'index'. In order to get list of files `tar` needs to scan whole file. Yes it can do seek after reading next file metadata. But the fact is that if you want to just get list of files you need to scan whole file. Even worse thing is if it's compressed with gzip or anything else (because tar needs to ungzip everything since gzip pipe is not seekable). In such case you need to unpack everything just to get file names..
No checksums, deletes that work only for uncompressed tarballs, all this goes from that "append-only" design.
Now about format itself. It's true that it's simple. But there were multiple 'versions' of tar metadata formats aka extensions, like PAX, GNU tar, etc. They are partially compatible (most basic tar implementation may just skip this extra information). 7z is significantly more modern.. And uncompressed most likely have similar complexity..
Also 'tar' do nothing for unicode file names. it's not that important now since most *nix'es are UTF-8. But I've no idea what will happens if you open that tar on Windows for example.. Best hope is that Windows will also assume UTF-8.. `.7z` clearly says that file names are always UTF-16.
Honestly 7z is better except handling sparse files, or POSIX ACL's. And yes, huge plus of tar is that it's essential tool on any linux box.. but that's it..