[tar] Compressed Archives
tar creates a compressed archive. the file extension of the resulting archive is
.tar and the tar archives are called
GNU ‘tar’ saves many files together into a single tape or disk archive, and can restore individual files from the archive.
.tar file is an archive, but it’s not compressed.
.tar.gz is a an archive that is compressed.
cis for create, –create a new archive
vis for –verbose, verbosely list files processed, list out files as they are added to the archive
fis for –file=ARCHIVE, use archive file or device ARCHIVE, basically, specify the tar file that you wanna create. Since
flets you take an input it should always be the last flag..
tar can also work off of STDIN and STDOUT,
f lets you specify if you wanna work with an existing tar file or if you wanna create one.
zis for compression, –compress (gzip) and –uncompress (gunzip)
xis for –extract
tis for –list, list the contents of an archive
ris for –append, add more files to an existing archive
uis for –update
-prestore permissions (can only be ysed with
-kKeep (don’t overwrite) existing files
compress a dir:
tar -cvf archive.tar dir-to-archive
compress multiple files
tar -cvf archive.tar file1 file2 file3
compress multiple files and dirs
tar -cvf archive.tar dir1 dir2 file2 file3
Compresses tar archives
You can compress on the fly with the
tar -czvf archive.tar.gz dir-to-archive
You can also use
gzip on a tarball to compress it.
x flag instead of
Extract all files from archive.tar.
tar -xf archive.tar
Extract a compressed tarball
tar -xzvf archive.tar.gz
Extract tarballs while restoring permissions
-p flag. It’s to
Restore permissions (including ACLs, owner, file flags)
List the contents of a tarball without extracting it
tar -tzvf archive.tar.gz
Handy when you wanna know what’s in a tarball, or to see if it’ll extract in the current dir or in it’s own subdir. Sometimes, you get a tar bomb when a tarball starts extracting all the files in your current dir instead of making its own folder.. Potentially clobbering files in your current dir, like README or something, that you might already have in the folder you are working in.
Getting a single file out of a tarball
Add more files to a previously created archive
Update the archive with new files
u flag. It updates the archive with new files, it also updates the existing files to their newer versions.
> only append files newer than copy in archive
Read compressed files
cat in a compressed file is
zcat to read files in an archive..
fshould be the last flag because it takes an option
- it makes more sense to start flags with
tso it’s clear right away if you are creating, extracting or listing..