How to Modify tar.gz file in windows? - tar

I have a tr.gz backup file, and I need to delete some file inside of this tar.gz file without extract the tar.gz file.
Is there any solution (command line or software) in windows?

It is not possible to remove the file from tar, but you can exclude a file by the following command
tar -zxvf file.tar.gz --exclude "file_to_exclude"
or
take a backup too and proceed
OR
tar -cvf files.tar --remove-files my_directory

Related

Extract a tar file to specific root dir regardless of the root dir inside the tar

I'm trying to extract a tar file where the contents of its dirs may change from time to time. I'd like to be able to extract the tar file regardless of what the root dir is. For example:
tar path and filename = /home/user/archive1.tar
If I run tar zxvf /home/user/archive1.tar -C /home/user then it's all extracted to /home/user/archive1 including any subdirs. The problem is that another tar file may extract to a different dir like /home/user/archive070320
What I need is to always extract to /home/user/myowndir and any files and subdirs that are in the tar file go to this dir. So even though inside the tar file it has a root dir of archive1 or archive0730320 or whatever, I'd like to replace that target rootdir with my own static root dir such as 'myowndir'
Also, it would really help if this could be done on one line and preferrably work on any Linux as well as AIX.

grep a tar.gz file where tar contains other gz files

I have a tar gz file. Inside the file are other directories and gz files and I am trying to recursively grep for a string. I have tried zgrep but the string I am searching for is not outputted even though I know it is there. What would be the command to do this?. The gz files inside the tar.gz files are *xml.gz files about 10k files.

docker add extract to custom directory

A docker add will nicely extract the supplied compressed file into the directory specified in the zip/tar file
How can I extract it into a different directory?
Eg. if the file extracts to /myfile but I would prefer /otherFile
Don't believe there's any way to do this just using the ADD instruction. ADD supports a target directory obviously, like ADD ["<src>", "<dest>"] however it's still going to extract into the dir you have in the tar within that.
2 options, either rename the dir in the tar or do a RUN mv myfile otherfile after adding.
Is there a specific reason you need it to be named something in particular?
Think about this scenario where you build a tomcat image,
ADD apache-tomcat-8.0.48.tar.gz /opt
This cmd will extract the tar to /opt/apache-tomcat-8.0.48 , if you don't like the long folder name(apache-tomcat-8.0.48) then the requirement happens.

How do I extract a TAR to a different destination directory

On server A, I created a tar file (backup.tar.gz) of the entire website /www. The tar file includes the top-level directory www
On server B, I want to put those files into /public_html but not include the top level directory www
Of course, tar -xzif backup.tar.gz places everything into /public_html/www
How do I do this?
Thanks!
You can use the --transform option to change the beginning of the archived file names to something else. As an example, in my case I had installed owncloud in directory named sscloud instead of owncloud. This caused problems when upgrading from the *.tar file. So I used the transform option like so:
tar xvf owncloud-10.3.2.tar.bz2 --transform='s/owncloud/sscloud/' --overwrite
The transform option takes sed-like commands. The above will replace the first occurrence of owncloud with sscloud.
Answer is:
tar --strip-components 1 -xvf backup.tar.gz

Tar Error [can not open: not a directory]

I have made some archive file with the tar gnome GUI on Ubuntu but when I try to extract them
tar zxvf archive_name
I get following error
Cannot open: Not a directory
What is the problem ?
Try extracting the archive in an empty directory; any existing files/directories in the extract target usually cause problems if names overlap.
I encountered the same issue (for each file within an archive) and I solved it by appending ".tar.gz" to the archive filename as I'd managed to download a PECL package without a file extension:
mv pecl_http pecl_http.tar.gz
I was then able to issue the following command to extract the contents of the archive:
tar -xzf pecl_http.tar.gz
You probably might already have a file with the same name that the tar is extracting a directory.
Try to tar in different location.
tar zxvf tar_name.tgz --one-top-level=new_directory_name
Try using tar -zxvf archive_name instead. I believe that the command format has changed, and it now requires the z (unzip) x (extract) v (verbose) f (filename...) parts as switches instead of plain text. The error comes from tar trying to do something to the file zxvf, which of course does not exist.

Resources