Quick Start: Here we’l present quick start examples explained.
Create linux tar gz (Gzip) archive
tar -czvf myarchive.tgz mydirectory/
We use the -t option to create an linux tar archive
-c, –create create a new archive
Note that .tgz is the same thing as .tar.gz
Create linux simple tar archive (withouth compresion)
tar -cvf myarchive.tar mydirectory/
Extracting linux tar archive:
Extract linux tar gz (Gzip) archive
tar -xzvf mystuff.tgz
Extract linux simple tar archive
tar -xvf mystuff.tar
We use -x to extract the files form the tar archive
-x, –extract, –get extract files from an archive
Extract linux tar archive to speciefied directory
tar -xvzf filename.tar.gz -C /desired/path
And now let us shortly explain this command
Usage: tar [OPTION]… [FILE]…
Let us check the option used in this example
-c, –create create a new archive
-z, –gzip, –ungzip filter the archive through gzip
-v, –verbose verbosely list files processed
-f, –file=ARCHIVE use archive file or device ARCHIVE
-C directory file
Performs a chdir operation on directory and performs the c (create) or r (replace) operation on file .
In c and r mode, this changes the directory before adding the following files. In x mode, change directories after opening the archive but before extracting entries from the archive.
Testing / viewing your archive
tar -tvf myarchive.tar
tar -tzvf myarchive.tgz
Here we used the – t opton
-t, –list list the contents of an archive
————————————————-
Go ahead, try out these commands and stay tuned; we will come up with more doccumentation on linux tar command
Tags: Linux, Linux Commands, tar, tar.gz
July 17, 2008 at 2:16 am |
Thanks for the great help keep the good work
August 13, 2008 at 12:38 pm |
Thanks, as newbe it surprises me that you cant extract to a defined location.
Copy the tarball to the root of the location first.
August 7, 2016 at 7:55 am |
in newer version, you can alread. just right click the flie then select “extract to”.
September 12, 2008 at 7:10 am |
Thanks for the great help keep the good work
October 11, 2008 at 4:29 pm |
[…] https://linuxbasiccommands.wordpress.com/2008/04/04/linux-tar-command/ […]
January 6, 2009 at 8:54 am |
You can extract to a defined location using:
tar xvf yourstuff.tar -C your/path/here
April 21, 2009 at 10:15 pm |
[…] above! You can extend this further by using cronjobs to run this command on a set schedule, compressing the files into a single archive file, and […]
February 6, 2011 at 7:10 pm |
how can i extract to a specified path?
February 10, 2011 at 5:30 pm |
You can extract to a specified path using:
tar xzvf yourarchive.tar.gz -C your/path/here
For this we will use -C ( not -c , wicht meand create )
-C directory file
Performs a chdir (see “cd” command ) operation on directory and performs the c (create) or r (replace) operation on file . Use short relative path names for file .
If file is `.’, archive all files in directory. This option enables archiving files from multiple directories not related by a close common parent.
August 1, 2011 at 3:25 pm |
regarding the “xzvf” do these commands have to specified in a specific order or do it not really matter as long as they are present?
August 19, 2011 at 2:24 pm |
The order doesn’t realy matter, they just need to be present.
April 4, 2012 at 2:56 pm |
[…] https://linuxbasiccommands.wordpress.com […]
September 4, 2012 at 8:54 am |
Thank you for posting this which helped a lot ….
June 26, 2013 at 1:13 pm |
if i have done
> tar -xvfz hugetarfile.tar.gz
and aborted it with ctrl+c
and found that hugetarfile.tar.gz has become tinytarfile.tar.gz
Is there any magic spells to make tinytarfile back to huge <.< , or the data loss is irreversible
September 19, 2013 at 5:20 am |
[…] https://linuxbasiccommands.wordpress.com/2008/04/04/linux-tar-command/ […]
April 28, 2014 at 1:57 pm |
When extracting an archive, the source should not change, I will try to replicate the situation …
November 5, 2014 at 2:56 am |
[…] https://linuxbasiccommands.wordpress.com/2008/04/04/linux-tar-command/ […]