I am new to Linux, I have a folder called stacey. How can I create a compressed tarball from this?
I can tar the folder with tar -cvzf stacey.tar *. But can I add the 7zip at the same time as so I have a compressed tarball called stacey.tar.gz ?
tar -cvz -f path_to_the_archive_to_be_created .
Example:
[user@machine temp]$ tar -cvz -f ~/dir1/temp.tar.gz .
The current directory (temp) is archived into ~/dir1/temp.tar.gz
tar -cvz -f path_to_the_archive_to_be_created -C path_to_the_remote_directory .
Example:
[user@machine ~]$ tar -cvz -f ~/dir1/temp.tar.gz -C ~/temp .
The directory ~/temp is archived into ~/dir1/temp.tar.gz.
-c, --create create a new archive
-v, --verbose verbosely list files processed
-z, --gzip, --gunzip, --ungzip filter the archive through gzip
-f, --file=ARCHIVE use archive file or device ARCHIVE
-C, --directory=DIR change to directory DIR
Passing -z on the tar command will gzip the file, so you should name your file stacey.tar.gz (or stacey.tgz), not stacey.tar:
tar -cvzf stacey.tar.gz *
If you want to 7zip the file (instead of Gzip), remove the -z, keep stacey.tar, and run 7z stacey.tar after the tar command completes:
tar -cvf stacey.tar *
7z a stacey.tar.7z stacey.tar
Or you can use a pipeline to do it in one step:
tar -cvf - * | 7z a -si stacey.tar.7z
7zip is more like tar in that it keeps an index of files in the archive. You can actually skip the tar step entirely and just use 7zip:
7z a stacey.7z *
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With