TAR
Updated on 28 Dec 2018
Linux TARBALL
TAR is an acronym for Tape Archive, and is a very common format for combining multiple files / folders into a single file. Often it is done with gzip to provide compression as well.
Create a TAR file
tar -zpcvf archivename.tar.gz directoryName
Where
- -z: Compress archive using gzip program
- -j: Compress archive using bz2 algorythm (smaller filesize, but takes longer)
- -c: Create archive
- -v: Verbose i.e display progress while creating archive
- -f: Archive File name
- -p: preserve the permissions
Extract a TAR file
tar -xvf archivename.tar.gz -C directoryName
Where
- -x: Extract files
- -v: Verbose i.e display progress while creating archive
- -f: Archive File name
- -C: Change directory (an error will occur if the directory does not exist)
-z
or -j
is not required anymore because tar will automatically decompress the file. It will decompress gz files and bz2 files automatically.
You can omit the -C directoryName
, and the file will automatically be extracted to the folder that was named during the initial tarball process.
List contents of a TAR file
tar -tvf archivename.tar.gz
Extract a single file
It is also possible to extract just a single file from the tarball. Simply provide the filename with the tar
command. Note, you will need to supply the path to the file!
tar -xvf archivename.tar.gz path_to_file/filename
Now you’ll be able to go to the directory and see your single file that you extracted.