You can remove members from an archive by using the --delete
option. Specify the name of the archive with --file=archive-name (-f archive-name) and then
specify the names of the members to be deleted; if you list no member
names, nothing will be deleted. The --verbose (-v) option will
cause tar
to print the names of the members as they are deleted.
As with --extract (--get, -x), you must give the exact member names when
using `tar --delete'. `--delete' will remove all versions of
the named file from the archive. The `--delete' operation can run
very slowly.
Unlike other operations, `--delete' has no short form.
This operation will rewrite the archive. You can only use `--delete' on an archive if the archive device allows you to write to any point on the media, such as a disk; because of this, it does not work on magnetic tapes. Do not try to delete an archive member from a magnetic tape; the action will not succeed, and you will be likely to scramble the archive and damage your tape. There is no safe way (except by completely re-writing the archive) to delete files from most kinds of magnetic tape. See section Tapes and Other Archive Media.
To delete all versions of the file `blues' from the archive `collection.tar' in the `practice' directory, make sure you are in that directory, and then,
$ tar --list --file=collection.tar blues folk jazz rock practice/blues practice/folk practice/jazz practice/rock practice/blues $ tar --delete --file=collection.tar blues $ tar --list --file=collection.tar folk jazz rock $
@FIXME{I changed the order of these nodes around and haven't had a chance to fix the above example's results, yet. I have to play with this and follow it and see what it actually does!}
The --delete option has been reported to work properly when
tar
acts as a filter from stdin
to stdout
.
Go to the first, previous, next, last section, table of contents.