TAR guidelines

Revision as of 01:56, 30 July 2021 by P.petrelli (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Tar: Tape ARchive cheat sheet

Some options

  • c – create archive file.
  • u - update archive file.
  • x – extract a archive file.
  • v – show the progress of archive file.
  • f – filename of archive file.
  • t – viewing content of archive file.
  • j – filter archive through bzip2.
  • z – filter archive through gzip.
  • r – append or update files or directories to existing archive file.
  • p - preserve-permissions
  • --acls - preserve acls 

Create tar archive

    tar -cvf archive.tar testdir

Create compressed tar archive

    tar -cvzf archive.tar.gz  testdir

Or for more compression but slower writing/uncompressing

    tar -cvfj archive.tar.bz2  testdir

Exclude only  files or directories with pattern

    tar -cvf archive.tar --exclude=”*.txt” testdir

There are many exclude options check with: man tar

Update tar archive

    tar -uvf archive.tar testdir

Will add for example previously excluded files and update any file which changed

Untar archive

    tar -xvf archive.tar 

tar -xvf archive.tar.gz 

    tar -xvf archive.tar.bz2 

    tar -xvf archive.tar -C /home/uncompress/here

List archive content

    tar -tvf archive.tar

Extract one file from tar archive

Need to use the full path for the file

So if you did:

tar -cvf archive.tar testdir

You use

tar -xf archive.tar testdir/readme.txt 

Extract multiple files from tar archive

tar -xvf archive.tar readme.txt another.txt

Or using wildcards

tar -xvf archive.tar *.txt

Add files or directories to tar archive

    tar -rvf archive.tar readme.txt

    tar -rvf archive.tar anotherdir