“Ultimate Guide to Archive Management: Mastering Tar and Zip Files”

Himanshu
2 min readJul 26, 2023

--

Tar files, or Tape archives, are common on Mac OS and Linux-based Systems.

Tar File Formats :

  1. tar.gz/.tgz ( gzip compression )
  2. tar.bz2 ( bzip compression )

So, we can say gzip and bzip are two methods of compressing .tar Files.

How to create a regular tar archive

>> tar cf file.tar filea.txt fileb.txt

Here, ‘c’ signifies creating a file, and ‘f ’ commands the tar command to output the archive to a file. Now, file.tar will be the name of the archive.

How to create compressed versions of TAR files

>> tar caf file.gz filea.txt fileb.txt

Here, ‘a’ tells tar to figure out the type of compression to use based on the file extension.

Or,

>> tar caf file.tar.bz2 filea.txt fileb.txt

This one takes more time but offers a little more compression.

Also, we can use normal zip like in Windows or Mac OS

>> zip file filea.txt fileb.txt

You can check the results with ‘ls -lh’.

Unpacking a compressed file

To do so, we have to create a separate directory. Since Unpacking in some place will overwrite every similar-looking file, So

>> mkdir one

>> tar xf file.tar -C one

x — stands for extract.

C — tells the path where you want to extract.

Now you can verify with ‘cd one’ then ‘ ls -l’

You’ll see uncompressed files.

Syntax for Unpacking

>> tar xf file.tar -C one

unpacks into a directory called one.

>> tar xf file.tar

unpacks into current directory.

Other commands for Unpacking

>> tar xf file.tar.gz -C directoryName

>> tar xf file.tar.bz2 -C directoryName

to unzip

>> unzip file.zip -d directoryName

Conclusion

Everyone working with huge amounts of data or files needs to have a basic understanding of managing archives. Data storage, transmission, and sharing are easier to manage when files are compressed and combined using the effective methods offered by the tar and zip formats. You can efficiently organize, create, extract from, and maintain archives if you grasp the methods presented in this article. Understanding tar and zip archives will surely increase your productivity and data management skills, whether you are a seasoned expert or a novice computer user. So go ahead and leverage the power of tar and zip archives to take control of your data and simplify your workflow.

--

--

Himanshu

🚀 Tech Maverick | MERN Stack Developer | Java | Python | Linux | Blogging Magic 📝