Commands.page Logo

How to Create a Gzip Compressed Archive in Ubuntu

Managing files efficiently is crucial for any Ubuntu user, especially when dealing with backups or transfers. This article explains the essential command-line tool used for compressing files into gzip archives. You will learn the basic syntax and options needed to reduce file size quickly and effectively within the Ubuntu terminal environment.

In Ubuntu, the standard utility for creating a gzip compressed archive is the tar command combined with the gzip compression flag. While gzip alone compresses individual files, tar allows you to bundle multiple files into a single archive before compressing them. This results in a .tar.gz file, which is the most common format for gzip compressed archives in Linux.

To create this archive, open your terminal and use the following syntax:

tar -czf archive_name.tar.gz /path/to/files

The flags used in this command serve specific functions. The -c option tells tar to create a new archive. The -z option filters the archive through gzip for compression. The -f option specifies the filename of the resulting archive. Replace archive_name.tar.gz with your desired file name and /path/to/files with the actual directory or files you wish to compress.

For example, to compress a folder named “documents” into an archive called “backup.tar.gz”, you would run:

tar -czf backup.tar.gz documents

This process creates a single compressed file containing all the data from the specified folder, ready for storage or transmission.