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?


2 Answers 2


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.


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
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.