Unix / Linux: Tar Command Remove a Directory From a Tar Ball

Posted on in Categories last updated September 20, 2011

How do I remove a directory from a tar ball under Unix / Linux operating systems?

The syntax to remove a directory from a tar ball is as follows:

tar --delete -f file.tar 'path1/dir1'

OR

tar --delete -f file.tar 'dir1'

To delete a directory called etc/security from a foo.tar, enter:
$ tar --delete -f foo.tar 'etc/security'
Verify that directory has been deleted from the foo.tar ball, enter:
$ tar -tvf foo.tar | less
OR
$ tar -tvf foo.tar | grep 'etc/security'

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

Leave a Comment