tar

Table of Contents

tar reference

flag mnemonic
-c create
-x extract
-t list
-v verbose
-z gzip
-C DIR change directory
-f FILE target file
$ cd /tmp
$ tree target
target
├── a.txt
└── path
    └── b.txt

$ tar -cvf target1.tar /tmp/target
tar: Removing leading '/' from member names
a tmp/target
a tmp/target/a.txt
a tmp/target/path
a tmp/target/path/b.txt

$ tar -xvf target1.tar
$ tree tmp
tmp
└── target
    ├── a.txt
    └── path
        └── b.txt

# Change directory
$ tar -C /tmp/target -cvf target2.tar .
a .
a ./a.txt
a ./path
a ./path/b.txt

$ mkdir out
$ tar -C out -xvf target2.tar
$ tree out
out
├── a.txt
└── path
    └── b.txt

# Exclude
$ tar -cvf target3.tar --exclude a.txt target
a target
a target/path
a target/path/b.txt

#+BEGIN_SRC sh
# Compression
$ tar -cvzf target.tar.gz target
a target
a target/a.txt
a target/path
a target/path/b.txt

# Don't need any option for extracting compressed tar
$ tar -xvf target.tar.gz
x target/
x target/a.txt
x target/path/
x target/path/b.txt

# List
$ tar -tvf target.tar.gz
drwxr-xr-x  0 hoey   staff       0 Jan 30 10:26 target/
-rw-r--r--  0 hoey   staff       0 Jan 30 10:23 target/a.txt
drwxr-xr-x  0 hoey   staff       0 Jan 30 10:26 target/path/
-rw-r--r--  0 hoey   staff       0 Jan 30 10:23 target/path/b.txt

# Untar a single file
$ tar -xvf target.tar.gz target/a.txt
x target/a.txt