Copy a file from nested tar.gz file

I have a situation where I want to extract a file from nested tar.gz. The structure of .tar.gz is as

  • test.tar.gz
    • data1
      • data2
        • data3
          • test2.tar.gz
            • data4
              • data5
                • test.log

I want to extract only test.log file from the test.tar.gz file. I have seen this post with which we can extract file of tar.gz but not in nested levels.

I am adding output of tar tfz data1.tar.gz The folder structure might be a bit different as entered the above structure manually.

 data1/. data1/META.json data1/TEMP data1/TEMP/temp-2 data1/TEMP/temp-2/1-chksum.txt data1/TEMP/temp-2/1 data1/TEMP/temp-2/1/otherfiles data1/TEMP/temp-2/1/otherfiles/2016_06_24.tar.gz 

So the test.log file is present within a nested folder inside 2016_06_24.tar.gz

Replay

Assuming that data4 & etc are members of the compressed test2.tar.gz archive,

tar -x -z -O -f ./test.tar.gz data1/data2/data3/test2.tar.gz | \
  tar xzf - --strip-components=2 data4/data5/test.log

... which tells the first tar to extract the nested compressed tar file to stdout, then tells the second tar to take that inputted file and extract only the data4/data5/test.log file, stripping the first two components out. That will drop the test.log file in your current directory.

Category: linux Time: 2016-07-28 Views: 0
Tags: linux tar

Related post

  • How can I run a program installed from a tar.gz file? 2011-02-12

    I have downloaded tar.gz files. But I don't know how to install it. How do I install this kind of file? --------------Solutions------------- The first thing you need to do is extracting it in a folder, let's make it your desktop. You can extract an a

  • How do I install virt-manager from a .tar.gz file? 2011-02-12

    I have downloaded tar.gz files. But I don't know how to install it. How do I install this kind of file? --------------Solutions------------- The first thing you need to do is extracting it in a folder, let's make it your desktop. You can extract an a

  • How do I extract a specific file from a tar archive? 2012-07-27

    Hi is possible to restore a single file from the .tar backup ? I dont want to restore total backup . i just want to restore one single file from the backup . --------------Solutions------------- 1. Using the Command-line tar Yes, just give the full s

  • Search for a file inside a tar.gz file without extracting it and copy the result to another folder 2013-10-17

    I need to search for a file inside a tar.gz file without extracting it. After that, I need to copy the file that was searched (if ever there is) to another folder. So far I have this, but the copy part of this line gives me an error. gunzip -c file.t

  • Extract a single file from a tar file and put it to another directory 2013-10-19

    This question already has an answer here: Search for a file inside a tar.gz file without extracting it and copy the result to another folder 2 answers I need to extract a single file from a tar file to another directory. So far I have this: This one

  • How can I flatten nested .tar.gz files? 2014-02-25

    I've got a bunch of .tar.gz files in different paths. I'd like to create a new .tar.gz file at some common ancestor of them and I don't want it to be composed of nested .tar.gz files. How can I easily flatten the archive once created? --------------S

  • TAR command to extract a single file from a .tar.gz 2010-04-08

    Does anyone have a command syntax for extracting 1 file from a .tar.gz that also allows me to place the extracted file in a certain directory? I have Googled this and get too many variations with a lot of forum threads stating the syntax doesn't work

  • Can Synaptic install application from a .tar.gz file downloaded from outside the repositories? 2013-11-13

    I would like to know if Synaptic package manager can install an application from a .tar.gz file downloaded from a different source than is in the repositories in /etc/apt/sources.list. I mean those files need to run ./configure , make, sudo make inst

  • Extract all files from a .tar.gz after wget and rename them 2015-06-12

    Is there any easy way extract all files from a .tar.gz and rename the files upon extraction? The tars inside look like: file1.obj file2.xr file3.ty file4.hjg All files are different extensions, but I want extract them and rename them the same, so the

  • How do i get the latest file from a list of files in a particular directory 2014-05-28

    I need to get the latest file from a list of files in a particular directory. When I run the script the first time I've copied the list of files in a particular directory to another directory. From the second run I need to get the latest files from a

  • How do I recover files from a corrupt VDI file? 2011-01-21

    Is it possible to repair a corrupt VDI file? The OS on the VDI (XP) doesn't boot at all, it just hangs at a black screen. I was getting file errors before on its last boot, but now its not working at all. Sector viewer shows 'Invalid partition table

  • Access to other local files from a local HTML file 2011-05-11

    I tried this question on programmers site with no luck Do you see any reason to block a local html file from accessing another local files located in the same folder? I mean, if a user downloaded an html app (consisting of several html files) and ope

  • Generating a monochrome PDF file from a color PDF file 2012-05-15

    How can I generate a monochrome pdf file from a color pdf file? I have tried ImageMagick's convert, but with bad results. A direct conversion convert -monochrome file.pdf file-bw.pdf produces dithered images. Going through png convert -monochrome -ba

  • How to stop ido-find-file from looking at my file's contents? 2014-03-26

    I use ido-find-file in emacs (through the "emacs starter kit"). There is one drawback I've found, namely that it uses the location in the file I'm currently editing as an extra hint. In some cases, this is handy, like when my point is somewhere

  • Creating a WAR file from a local WSDL file 2016-01-17

    Is it possible to create a war file from a local wsdl file? I've tried to create a web service in eclipse using the wsdl file and then export the web project to a war file, but when I deploy the created war in glassfish, the deployed web service does

  • How to pull single file from multiple similar named file using sftp 2016-07-22

    I want to pull a single file from multiple similar named file using sftp. Eg. if my remote server is having below files, file_0722_005.dat file_0722_020.dat file_0722_033.dat file_0722_0022.dat I just want to pull any one among them. In unix I can go

  • How to copy previous output from bash terminal to file 2010-10-26

    I know how to redirect the output of a terminal to a file. For example, if I want to list all the files in ~/Documents and output to a file called test.txt, I would do this: ls ~/Documents > test.txt The question is, can I copy the output to test.txt

  • Extract a single file from a tar file to another directory 2013-10-22

    I have a tar file and I need to extract a single file from it and put it to another directory. I tried this but it gives an error message. It did extract the file but not to the directory that I want but it extracted the file to the same directory. t

  • Relocate jpg files from nested/buried structure to relative known directories 2014-07-16

    I'm trying to batch move/organize a large number of files (.jpg) from nested subdirectories to a relative directory. The structure is pre-planned. Just not 100% sure what the most efficient and safest way to do it is. Sample structure: /directory/sub

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 1.045 (s). 13 q(s)