Home » linux-commands » How to delete and modify files from compress archive tarball without extracting

How to delete and modify files from compress archive tarball without extracting

If you have an unuse directory and file in a compress archive (.tar) file, and want to remove it without extracting the entire archive. you done by using following steps if you have a big file and don’t want to spend a lot of time extracting and re-archiving. So open up a terminal window and follow as given below.
First of all list compressed tarball named backupfile.tar.gz and verify what type of contents have it by using the –list option.

root@linuxpcfix [/home/user] tar –list –file=backupfile.tar.gz
backupfile
backupfile/fp/
backupfile/fp/sites/
backupfile/resellerfeatures/
backupfile/suspendinfo/
backupfile/logs/
backupfile/mysql/
backupfile/homedir/

Then try to delete the directory called backupfile/logs from the compressed file:

root@linuxpcfix [/home/user]# tar –delete –file=backupfile.tar.gz backupfile/logs
tar: Cannot update compressed archives
tar: Error is not recoverable: exiting now

If you are seeing as above That means you have to uncompress it as modify or delete files operation generally not allowed from compressed file like tar.gz or tar.bz2.
So uncompress the tar.gz archive by using gunzip command as below.

root@linuxpcfix[/home/user]# gunzip backupfile.tar.gz

after that try to delete the directory backupfile/logs again:

root@linuxpcfix[/home/user]# tar –delete –file=backupfile.tar backupfile/logs

Now you should not get an error message, so that’s excellent. and verify if it’s delete or not by using –list again:

root@linuxpcfix[/home/user]# tar –list –file=backupfile.tar
backupfile
backupfile/fp/
backupfile/fp/sites/
backupfile/resellerfeatures/
backupfile/suspendinfo/
backupfile/mysql/
backupfile/homedir/

Excellent! The directory backupfile/logs has been deleted.

About

I am founder and webmaster of www.linuxpcfix.com and working as a Sr. Linux Administrator (Expertise on Linux/Unix & Cloud Server) and have been in the industry from last 7 years.

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*

Time limit is exhausted. Please reload the CAPTCHA.

Categorized Tag Cloud