The Bandwidth Preservation Vector
When operating a headless Ubuntu server, you will frequently need to backup massive directories—such as an entire web server root (`/var/www/html`) or a directory containing millions of system logs. Attempting to download or transfer these files individually over an SSH connection or an FTP client will take hours due to network overhead. You must compress the entire directory structure into a single, highly condensed archive file before initiating the transfer.
How to Compress a Folder
The undisputed standard for compression in the Linux ecosystem is the “tarball,” generated by combining the tar (tape archive) utility with the gzip compression algorithm.
1. Open your terminal application or connect to your server via SSH.
2. Navigate to the directory containing the folder you wish to compress. For example, if you want to compress a folder named website_backup located in your home directory, type cd ~.
3. Execute the following command structure exactly, replacing archive_name.tar.gz with your desired final filename, and target_folder/ with the actual name of the directory you are compressing:
tar -czvf archive_name.tar.gz target_folder/
4. Command Breakdown:
* -c (Create): Instructs the utility to create a new archive, not extract one.
* -z (Gzip): Forces the utility to violently compress the resulting archive to save space.
* -v (Verbose): Prints the name of every single file to the terminal screen as it is processed.
* -f (File): Specifies the name of the final archive.
Depending on the size of the directory, the terminal will print a rapidly scrolling list of files for several seconds or minutes. Once it returns to a blank prompt, your newly compressed `.tar.gz` file will be ready for transfer.