TAR

01.jpg

File compression is an essential utility across all platforms. It helps you reduce file size and share files efficiently. And compressed files are also easier to copy to remote servers.

You can also compress older and rarely used files and save them for future use which helps you conserve disk space.

In this post, we'll look at how to compress files with the command in Linux, along with some examples of in action.

Create a .tar file

tar -cvf filename.tar /path/to/directory/

Create a .tar.gz file

tar -czvf filename.tar.gz /path/to/dir1

Extract a .tar file

tar -xvf foo.tar

Extract and uncompressed a .tar.gz file

tar -xvzf foo.tar.gz

Extract into a folder called my_folder

tar -xzvf filename.tar.gz -C my_folder/

Extract and uncompressed a tar.bz2 file

tar -xvjf foo.tar.bz2

Tar archives can be split into multiple archives of a certain size, which is handy if you need to put a lot of content onto discs. It’s also useful if you have a huge archive that you need to upload, but would rather do it in chunks. In this guide, we’ll show you the commands you need in order to split tar archives into multiple blocks on a Linux system.

This will work regardless of what type of compression (or lack thereof) that you use. So files with extensions like .tar, tar.gz, tar.xz, etc. can all be split into chunks. We’ll also show you how to extract files from archives that have been split into numerous files.

make compress and split archive 4 GB max per package

tar czpvf - /path/to/archive | split -d -b 4096M - tardisk

Extract the split tar archive

cat tardisk* | tar xzpvf -

make compress and split archive tar.gz 200 MB max per package

tar cvzf - dir/ | split --bytes=200MB - sda1.backup.tar.gz.

Extract the split tar.gz archive

cat sda1.backup.tar.gz.* | tar xzvf -