I would like to zip up my homework from last year. How do I tar and zip the whole folder from command line Ubuntu (I don't have GUI).
5 Answers
Use the following one-liner:
tar cf - <source folder> | 7z a -si <Destination archive>.tar.7z
It is not a good idea compressing directly with 7z spcially on unix/linux systems: 7z does not preserve permissions and or user/group info. So: first tar, and then compress.
As reported on 7zip wiki page at http://en.wikipedia.org/wiki/7z#Limitations :
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.
Read man tar
. It offers:
-a, --auto-compress
use archive suffix to determine the compression program
-j, --bzip2
--lzip
--lzma
--lzop
-z, --gzip, --gunzip --ungzip
-Z, --compress, --uncompress
Or, if none of those is right for you, and you have a compression program that reads stdin
, you could:
tar cf- $HOME | my_compression_program >/tmp/compressed.output
Note that I'm writing the output somewhere other than $HOME
(backing up into a directory that you're backing up leads to unconstrained file growth).
Or, you could read man 7z
- it looks like you could do
dir="directory to save"
7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on /tmp/archive.7z $dir
I would suggest that you use:
tar cf - foldername | 7z a -si -m0=lzma2 -mx=3 foldername.tar.7z
for dramatic speedup increase.
It has the advantage of using lzma2 (-m0=lzma2
) (which utilizes max available cores on your system and "Fast compression" preset (-mx=3
), which is basically fast and good enough.
Note that LZMA2 is not only utilizing all cores on compression, but also on decompression.
-
1Finally, with your answer, I've found what I was looking for: the ability to use all processors on the task. Sep 6, 2019 at 1:58
You should use tar -Jchf <Filename>.tar.xz <Files to compress>
The -J
uses the XZ compression algorithm, the same as 7zip
-c
creates a new file
-h
preserves simlinks
-f
sets the filename
-
I have checked with -J, it reduce double size in sql database file. Feb 29 at 12:52