How to archive and 7z each file individually from a folder?
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to archive and 7z each file individually from a folder?
In ubuntu 17.04, There are many files and folders in one parent folder, how i tar and 7z each one with one command, i read and tried this one:
Code:
tar -cf | for i in *; do 7za a $i.tar.7z $i; if [ $? -eq 0 ]; then rm -rf $i; fi; done
i run this code inside the parent folder and working well, but when i want to extract the archive with this command get the error:
Code:
7za x -so stardict-babylon-Babylon_English-2.4.2.tar.7z | tar xf -
tar: Archive is compressed. Use -z option
tar: Error is not recoverable: exiting now
Tar has options to specify the archive (or de-archive) program to use on the command line. It seems to me that using that option would be more efficient and straightforward.
I do not get it . did you try that "tar: Archive is compressed. Use -z option" ? and see if that unzipped the files?
The "z" option uses the gzip format. The "j" options uses the bzip2 format. There is now an "xz" option to use the XZ format.
To use 7z format will require an option to specify the 7z tools on the command line.
I believe it is I or --use-compress-program in the gnu version of tar.
The "z" option uses the gzip format. The "j" options uses the bzip2 format. There is now an "xz" option to use the XZ format.
To use 7z format will require an option to specify the 7z tools on the command line.
I believe it is I or --use-compress-program in the gnu version of tar.
not to sure how relevant this is, but it does address 7z and tar and Unix based systems.
Quote:
Limitations
The 7z format does not store filesystem permissions (such as UNIX owner/group permissions or NTFS ACLs), and hence can be inappropriate for
backup/archival purposes. A workaround on UNIX-like systems for this is to convert data to a tar bitstream before compressing with 7z. But it is worth
noting that GNU tar (common in many UNIX environments) can also compress with the LZMA algorithm natively, without the use of 7z, and that in this case
the suggested[5] file extension for the archive is ".tar.lzma" (or just ".tlz"), and not ".tar.7z". On the other hand, it is important to note, that tar
does not save the filesystem encoding, which means that tar compressed filenames can become unreadable if decompressed on a different computer. It is
also possible to use LZMA2 by running it through the xz tool. Recent versions of GNU tar support the -J switch, which runs TAR through XZ. The file extension is ".tar.xz" or ".txz". This method of compression has been adopted with many distributions for packaging, such as Arch, Debian (deb), Fedora
(rpm) and Slackware.
The 7z format does not allow extraction of some "broken files"—that is (for example) if one has the first segment of a series of 7z files, 7z cannot give
the start of the files within the archive—it must wait until all segments are downloaded. The 7z format also lacks recovery records, making it
vulnerable to data degradation. By way of comparison, zip files also lack a recovery feature. In contrast the proprietary rar format permits recoveries
as well as the extraction of broken files and file spanning.
I find the last post by BW-userx pertinent and helpful.
Check your man page for tar, and make use of the native tar command-line for best results.
Note that the compression you use must be installed (or at least the required libs installed) as tar does not do the compression internally/natively. It generally calls the same compression library routines used by the command-line compression tools.
(IE: if you ahve not installed XZ then the XZ options MAY not work.)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.