Logo
  • Ubuntu
  • CentOS
  • Debian
  • Fedora
  • RedHat

How to Create Tar Gz File - DesignLinux

designlinux 0 Comments

A tar archive is a file that stores a collection of other files, including information about them, such as the ownership, permissions, and timestamp.

In Linux operating systems, you can use the tar command to create tar archives. The command can also compress archives using a vast range of compression programs with gzip is the most popular algorithm.

By convention, the name of a tar archive compressed with gzip should end with either .tar.gz or .tgz.

This article describes how to create tar.gz files.

Creating tar.gz File #

Most Linux distributions come include the GNU version of tar that supports compressing archives.

The general form of the command for creating tar.gz files is as follows:

tar -czf archive-name.tar.gz file-name...

Here’s what the command options mean:

  • -c – instructs tar to create a new archive.
  • -z – sets the compression method to gzip.
  • -f archive-name.tar.gz – specifies the archive name.
  • file-name... a space-separated list of files and directories to be added to the archive.

The user running the command must have write permissions on the directory where the tar.gz file will be created, and read permissions on the files being added.

For example, to create an archive named “archive.tar.gz” from “file1” and “file2” you would use the following command:

tar -czf archive.tar.gz file1 file2

On success, the command doesn’t print any output. To verify that the archive is created, list the directory contents with ls .

Use the -v option to make the tar command more visible and print the names of the files being added to the archive on the terminal.

If you want to create the tar.gz in a specific directory, provide a full path to the archive file:

tar -czf /home/user/archive.tar.gz file1 file2

You can create tar.gz files from the contents of one or more directories or files. By default, directories are archived recursively unless --no-recursion option is specified.

The following example shows how to create an archive named “web_backup.tar.gz” of the /var/www/website directory:

tar -czf web_backup.tar.gz /var/www/website

If you are running a system that has an older version of tar that doesn’t support compression, you can use the gzip command:

tar -czf - file1 file2 | gzip > archive.tar.gz

In the example above, the tar command outputs the archive to stdout (represented by -). The archive is piped to gzip, which compress and write the archive to the disk.

Examples #

  • Create a tar.gz file from all “.jpg” files:

    tar -czf images.tar.gz *.jpg

    The wildcard character (*) means all files that end with “.jpg” extension.

  • Create a tar.gz file, transfer it over ssh and extract it on the remote machine:

    tar cvf - project | ssh user@ip_addr "tar xv -C /var/www"

Conclusion #

tar.gz file is a Tar archive compressed with Gzip. To create a tar.gz file, use the tar -czf command, followed by the archive name and files you want to add.

If you have any questions, please leave a comment below.

tar terminal

Related

Tags: tar, terminal

How to Install Steam on Ubuntu 20.04

Prev Post

How to Install TensorFlow on CentOS 8

Next Post
Archives
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • July 2022
  • June 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
Categories
  • AlmaLinux
  • Android
  • Ansible
  • Apache
  • Arch Linux
  • AWS
  • Backups
  • Bash Shell
  • Bodhi Linux
  • CentOS
  • CentOS Stream
  • Chef
  • Cloud Software
  • CMS
  • Commandline Tools
  • Control Panels
  • CouchDB
  • Data Recovery Tools
  • Databases
  • Debian
  • Deepin Linux
  • Desktops
  • Development Tools
  • Docker
  • Download Managers
  • Drupal
  • Editors
  • Elementary OS
  • Encryption Tools
  • Fedora
  • Firewalls
  • FreeBSD
  • FTP
  • GIMP
  • Git
  • Hadoop
  • HAProxy
  • Java
  • Jenkins
  • Joomla
  • Kali Linux
  • KDE
  • Kubernetes
  • KVM
  • Laravel
  • Let's Encrypt
  • LFCA
  • Linux Certifications
  • Linux Commands
  • Linux Desktop
  • Linux Distros
  • Linux IDE
  • Linux Mint
  • Linux Talks
  • Lubuntu
  • LXC
  • Mail Server
  • Manjaro
  • MariaDB
  • MongoDB
  • Monitoring Tools
  • MySQL
  • Network
  • Networking Commands
  • NFS
  • Nginx
  • Nodejs
  • NTP
  • Open Source
  • OpenSUSE
  • Oracle Linux
  • Package Managers
  • Pentoo
  • PHP
  • Podman
  • Postfix Mail Server
  • PostgreSQL
  • Python
  • Questions
  • RedHat
  • Redis Server
  • Rocky Linux
  • Security
  • Shell Scripting
  • SQLite
  • SSH
  • Storage
  • Suse
  • Terminals
  • Text Editors
  • Top Tools
  • Torrent Clients
  • Tutorial
  • Ubuntu
  • Udemy Courses
  • Uncategorized
  • VirtualBox
  • Virtualization
  • VMware
  • VPN
  • VSCode Editor
  • Web Browsers
  • Web Design
  • Web Hosting
  • Web Servers
  • Webmin
  • Windows
  • Windows Subsystem
  • WordPress
  • Zabbix
  • Zentyal
  • Zorin OS
Visits
  • 5
  • 501
  • 612,680

DesignLinux.com © All rights reserved

Go to mobile version