0

When you extract a individual file from a tar compressed directory (How to extract specific file(s) from tar.gz) does a copy of this file remain compressed or is it completely removed from the directory?

For example:

$ tar -zxvf mydir.tar.gz file1.txt

Will file1.txt remain stored in the mydir.tar.gz?

slm
  • 369,824
Graeme
  • 11

2 Answers2

1

Of course the tar file, whether compressed or not, is not modified.

There is no "tar compressed directory". There may be a compressed tar file containing the content of zero or more directories.

RalfFriedl
  • 8,981
0

A simple test shows that the file remains within the archive, even after a copy is extracted from it.

contents of tarball

$ tar ztvf somedir.tar.gz
drwxrwxr-x vagrant/vagrant   0 2018-08-08 00:33 somedir/
-rw-rw-r-- vagrant/vagrant   6 2018-08-08 00:33 somedir/file2.txt
-rw-rw-r-- vagrant/vagrant   6 2018-08-08 00:33 somedir/file1.txt

size of file, 181 bytes

$ ll
total 4
-rw-rw-r-- 1 vagrant vagrant 181 Aug  8 00:33 somedir.tar.gz

extract a file from tarball

$ tar zxvf somedir.tar.gz somedir/file1.txt
somedir/file1.txt

after extracting a file

$ ll
total 8
drwxrwxr-x 2 vagrant vagrant 4096 Aug  8 00:35 somedir
-rw-rw-r-- 1 vagrant vagrant  181 Aug  8 00:33 somedir.tar.gz

Size of tarball remains 181 bytes throughout.

slm
  • 369,824