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 extract.
The tar command will extract all the files/folders in the archive to the current directory.
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.
The tar command will extract all the files/folders in the archive to the current directory.
~Fin
Too often I figure out how to do this or that on Linux systems and in my haste to complete whatever task I've been assigned this "How To" knowledge gets lost. So here, I will begin posting little odds and ends in hopes of not needing to re-research past efforts for Linux tips, tricks, hacks, and other good to know things. If you find yourself here and know of smaller, faster, better ways of doing any of this please let me know - only through cooperation can we all get better.
Showing posts with label compression. Show all posts
Showing posts with label compression. Show all posts
Wednesday, October 14, 2009
Subscribe to:
Posts (Atom)