User Tools

Site Tools


tar_usage

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
tar_usage [2020/12/04 15:47] rajutar_usage [2023/01/26 21:20] raju
Line 1: Line 1:
-=== relative file names in the archive === +==== count number of lines in a txz file ====
-==== Problem ==== +
-If we tar the following directory+
 <code> <code>
-% tree --charset=unicode /tmp/expt +xz -cd foo.txz wc -l
-/tmp/expt +
-`-- insurance +
-    |-- auto.txt +
-    |-- condo.txt +
-    `-- rv.txt +
- +
-1 directory, 3 files +
-</code> +
-using +
-<code> +
-% tar czvf insurance.tgz /tmp/expt/insurance  +
-tar: Removing leading `/' from member names +
-/tmp/expt/insurance/ +
-/tmp/expt/insurance/auto.txt +
-/tmp/expt/insurance/rv.txt +
-/tmp/expt/insurance/condo.txt +
-</code> +
-then the file names in the .tgz contain the whole path releative to '/'+
-<code> +
-% tar tzvf insurance.tgz                    +
-drwxr-xr-x rajulocal/rajulocal 0 2020-12-04 10:25 tmp/expt/insurance/ +
--rw-r--r-- rajulocal/rajulocal 0 2020-12-04 10:25 tmp/expt/insurance/auto.txt +
--rw-r--r-- rajulocal/rajulocal 0 2020-12-04 10:25 tmp/expt/insurance/rv.txt +
--rw-r--r-- rajulocal/rajulocal 0 2020-12-04 10:25 tmp/expt/insurance/condo.txt +
-</code> +
-But I want the paths to be relative to the 'insurance' directory. Something like +
-<code> +
-drwxr-xr-x rajulocal/rajulocal 0 2020-12-04 10:25 insurance/ +
--rw-r--r-- rajulocal/rajulocal 0 2020-12-04 10:25 insurance/auto.txt +
--rw-r--r-- rajulocal/rajulocal 0 2020-12-04 10:25 insurance/rv.txt +
--rw-r--r-- rajulocal/rajulocal 0 2020-12-04 10:25 insurance/condo.txt+
 </code> </code>
  
-==== Solution ==== 
-Use the -C option while creating the tar archive. 
 <code> <code>
-% tar czvf insurance2.tgz -C /tmp/expt insurance +for i in *.txz; do echo $i; xz -cd $| wc; done
-insurance/ +
-insurance/auto.txt +
-insurance/rv.txt +
-insurance/condo.txt +
-</code> +
-Test the archive. +
-<code> +
-% tar tzvf insurance2.tgz                        +
-drwxr-xr-x rajulocal/rajulocal 0 2020-12-04 10:25 insurance/ +
--rw-r--r-- rajulocal/rajulocal 0 2020-12-04 10:25 insurance/auto.txt +
--rw-r--r-- rajulocal/rajulocal 0 2020-12-04 10:25 insurance/rv.txt +
--rw-r--r-- rajulocal/rajulocal 0 2020-12-04 10:25 insurance/condo.txt +
-</code> +
-==== How it works ==== +
-From the man page +
-<code> +
-% man tar +
-... +
-       -C, --directory=DIR +
-              Change  to DIR before performing any operations.  This option is order-sensitive, i.e. it affects all +
-              options that follow.+
 </code> </code>
  
-==== System information ==== + 
-Debian Buster +==== internal links ==== 
-<code> +  * [[Relative file names in a tar archive]] 
-% tar --version + 
-tar (GNU tar) 1.30 + 
-</code>+
tar_usage.txt · Last modified: 2023/01/26 21:24 by raju