I have a .7z file containing ~360,000 images in multiple directories. I'd like to convert it to a .tar so that I can open it in another computer. Is there a better way than extracting it to files and compressing them again? Is it possible to do the conversion directly?
.7z
archives are archives often compressed with some kind of algorithm, while.tar
archives are just archives.They differ in their scope, and in most cases a conversion would require an optional decompression always followed by an extraction of the source archive. Even if a
.7z
archive wouldn't use any compression it would still require an extraction.That being said, If you meant to [decompress] / extract / rearchive the source archive at once, the answer is you can't, at least not using Ubuntu's default tools because
tar
can't read fromstdin
, so you can't pipe7z
andtar
. Anyway it's very easy to automate everything in a single command:* <path_to_archive> = path to the source
.7z
archiveAlso the time required for the source archive's files to be written to the disk and for the extracted files to be read in order to [decompress] / extract / rearchive the source archive in two steps is a bottleneck for the whole task mostly (altough not only) because of a potential disk's low I/O speed, so a partial solution would be to store the temporary files to a ramdisk in order to almost void the overall bottleneck:
sudo mkdir /mnt/tmpfs
sudo mount -t tmpfs -o size=<tmpfs_size> tmpfs /mnt/ramdisk
* <tmpfs_size> = size of the filesystem in bytes * 103 (1, 1K, 1M, 1G, ...)mkdir /mnt/tmpfs/tmp && 7z x <path_to_source_archive> -o/mnt/tmpfs/tmp && tar cf archive.tar /mnt/tmpfs/tmp && rm -rf /mnt/tmpfs/tmp
* <path_to_archive> = path to the source.7z
archivesudo umount
sudo rmdir /mnt/tmpfs
It's not too hard to write something to do the job. Here's an example Perl script (requires the module Archive::Libarchive::XS).
If you wanted a tar.gz / tar.bz2 / tar.xz archive, add the line
archive_write_add_filter_gzip($out);
orarchive_write_add_filter_bzip2($out);
orarchive_tar_add_filter_xz($out);
after thearchive_write_set_format
line.This uses no temporary disk space (just the space for the output tar file) and very little RAM (just a few MB for perl, but it works with the files a block at a time, so it's not a problem if your files are bigger than your RAM).