[Tutor] Removing a file from a tar

Jacob S. keridee at jayco.net
Thu Jun 28 12:03:53 CEST 2007

>* Adam A. Zajac <strider1551 at gmail.com> [2007-06-27 11:26]:
>> I was reading over the documentation for the tarfile module and it
>> occurred to me that there didn't seem to be a way to remove an
>> individual file from the tar.
>> For example, suppose I did this:
>> import tarfile
>> tar = tarfile.open("sample.tar", "w")
>> tar.add("unwanted")
>> tar.add("wanted")
>> tar.close()
>> At this point, how could I come back and remove "unwanted" from the tar?
> Wel, it looks like tar's --remove-files is not supported yet, you would
> probably have to reopen the tarfile, write it to a new one file-by-file,
> excluding the ones you don't want.  Messy :-(

Disclaimer: I was not alive during the described era. This information may 
be off or just plain wrong. Perhaps someone who was alive then will correct 
any errors(?).

Remove is not supported because of the way tar s were designed. They were 
designed for tape drive backups, that is 'tar' Tape ARchive. Because they 
were designed as a backup scheme for tape drives, there was no need to have 
a remove function.

|  File1 | File2 | File3 |
Remove File2
| File1 |       | File3|

Moving file3 up would mean that the tape would have to rock back and forth, 
something that tapes just weren't supposed to do. Not moving file3 up would 
very nearly defeat the purpose of deleting file2 in the first place: to save 
space. (Which was important then - and should be now... tsk, tsk Microsoft)

Anyway, there was no need to have a remove function because people just did 
what Adam said - write a whole new tape. Now that tar is no longer widely 
used for tapes, there are other formats (like RAR) that *are* designed for 
modern storage equipment.


More information about the Tutor mailing list