How to Create & Extract tar.gz and tar.bz2 Files in Linux
Labels:
Command Line Utilities,
File System
The most common compressed archive file format in Linux is the tar.gz format. Tar file is an archive file format. Tar.gz is a compressed tar file.
How to create a compressed tar.gz file from a folder or file in Linux?
In order to create a compressed tar.gz archive from a folder/file we need to run the following tar command:
tar czf new-tar-file-name.tar.gz file-or-folder-to-archive
Here is the command explanation:
- tar - the tar command.
- c - create new archive.
- z - compress the archive using gzip.
- f - use archive file.
- new-tar-file-name.tar.gz - the name of the tar.gz to create.
file-or-folder-to-archive - the name of the folder we want to archive.
How to create a compressed tar.gz file from multiple files and folders in Linux?
In order to create a compressed tar.gz file from multiple files or/and folders we need to run the same tar command we used when we archived a single file/folder and to append the rest of the files/folders' names to it.
tar -czf new-tar-file-name.tar.gz file1 file2 folder1 folder2
How to extract a compressed tar.gz file in Linux?
tar -xzf tar-file-name.tar.gz
Here is the command explanation:
- tar - the tar command.
- x - extract the archive.
- z - uncompress the archive using gzip.
- f - use archive file.
tar-file-name.tar.gz - the name of the tar.gz to create.
How to extract a compressed tar.bz2 file in Linux?
Extracting tar.bz2 (bzip2 file) is very similar to the way you extract tar.gz file. Instead of using the -z flag you need to use the -j flag for the bzip2 format
tar -xjf tar-file-name.tar.gz
Here is the command explanation:
- tar - the tar command.
- x - extract the archive.
- j - filter the archive through bzip2
- f - use archive file.
tar-file-name.tar.gz - the name of the tar.gz to create.
Subscribe to:
Post Comments (Atom)
Post a Comment