untar file without subdirectories containing it [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite













This question already has an answer here:



  • How to extract only files without creating directory paths from tar.gz file?

    2 answers



I have a tar archive foo.tar.gz, inside of which a directory containing another directory contains a file: folder_1/folder_2/file.txt.



I want to untar file.txt without extracting folder_1/folder_2/.



Using



tar -xvf foo.tar.gz folder_1/folder_2/file.txt


I get file.txt inside the subdirectories that contained it inside the tar archive (folder_1/folder_2/file.txt).



Is there a way of getting only file.txt and nothing else in a single command, avoiding extracting everything?







share|improve this question














marked as duplicate by αғsнιη, Jeff Schaller, G-Man, Isaac, Archemar Feb 9 at 6:12


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















    up vote
    1
    down vote

    favorite













    This question already has an answer here:



    • How to extract only files without creating directory paths from tar.gz file?

      2 answers



    I have a tar archive foo.tar.gz, inside of which a directory containing another directory contains a file: folder_1/folder_2/file.txt.



    I want to untar file.txt without extracting folder_1/folder_2/.



    Using



    tar -xvf foo.tar.gz folder_1/folder_2/file.txt


    I get file.txt inside the subdirectories that contained it inside the tar archive (folder_1/folder_2/file.txt).



    Is there a way of getting only file.txt and nothing else in a single command, avoiding extracting everything?







    share|improve this question














    marked as duplicate by αғsнιη, Jeff Schaller, G-Man, Isaac, Archemar Feb 9 at 6:12


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite












      This question already has an answer here:



      • How to extract only files without creating directory paths from tar.gz file?

        2 answers



      I have a tar archive foo.tar.gz, inside of which a directory containing another directory contains a file: folder_1/folder_2/file.txt.



      I want to untar file.txt without extracting folder_1/folder_2/.



      Using



      tar -xvf foo.tar.gz folder_1/folder_2/file.txt


      I get file.txt inside the subdirectories that contained it inside the tar archive (folder_1/folder_2/file.txt).



      Is there a way of getting only file.txt and nothing else in a single command, avoiding extracting everything?







      share|improve this question















      This question already has an answer here:



      • How to extract only files without creating directory paths from tar.gz file?

        2 answers



      I have a tar archive foo.tar.gz, inside of which a directory containing another directory contains a file: folder_1/folder_2/file.txt.



      I want to untar file.txt without extracting folder_1/folder_2/.



      Using



      tar -xvf foo.tar.gz folder_1/folder_2/file.txt


      I get file.txt inside the subdirectories that contained it inside the tar archive (folder_1/folder_2/file.txt).



      Is there a way of getting only file.txt and nothing else in a single command, avoiding extracting everything?





      This question already has an answer here:



      • How to extract only files without creating directory paths from tar.gz file?

        2 answers









      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 8 at 14:01









      Jeff Schaller

      31.3k846105




      31.3k846105










      asked Feb 8 at 13:21









      tli

      234




      234




      marked as duplicate by αғsнιη, Jeff Schaller, G-Man, Isaac, Archemar Feb 9 at 6:12


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by αғsнιη, Jeff Schaller, G-Man, Isaac, Archemar Feb 9 at 6:12


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          You can extract the file to standard output and redirect that:



          tar -xvf foo.tar.gz -O folder_1/folder_2/file.txt > file.txt


          (Note that the option is a capital “O”, not the digit “0”.)






          share|improve this answer






















          • I am getting this printed out, and my file.txt gets extracted without any content: tar: Options '-[0-7][lmh]' not supported by *this* tar Try 'tar --help' or 'tar --usage' for more information.
            – tli
            Feb 8 at 14:00










          • @tli Are you using -O (capital letter O), or -0 (number 0)? The capital letter O option is a GNU tar extension to extract to stdout.
            – Andrew Henle
            Feb 8 at 14:06











          • @AndrewHenle my bad, thanks for pointing that out, now it works!
            – tli
            Feb 8 at 14:12










          • The option is also supported on other platforms, e.g. FreeBSD.
            – Stephen Kitt
            Feb 8 at 14:13

















          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote



          accepted










          You can extract the file to standard output and redirect that:



          tar -xvf foo.tar.gz -O folder_1/folder_2/file.txt > file.txt


          (Note that the option is a capital “O”, not the digit “0”.)






          share|improve this answer






















          • I am getting this printed out, and my file.txt gets extracted without any content: tar: Options '-[0-7][lmh]' not supported by *this* tar Try 'tar --help' or 'tar --usage' for more information.
            – tli
            Feb 8 at 14:00










          • @tli Are you using -O (capital letter O), or -0 (number 0)? The capital letter O option is a GNU tar extension to extract to stdout.
            – Andrew Henle
            Feb 8 at 14:06











          • @AndrewHenle my bad, thanks for pointing that out, now it works!
            – tli
            Feb 8 at 14:12










          • The option is also supported on other platforms, e.g. FreeBSD.
            – Stephen Kitt
            Feb 8 at 14:13














          up vote
          2
          down vote



          accepted










          You can extract the file to standard output and redirect that:



          tar -xvf foo.tar.gz -O folder_1/folder_2/file.txt > file.txt


          (Note that the option is a capital “O”, not the digit “0”.)






          share|improve this answer






















          • I am getting this printed out, and my file.txt gets extracted without any content: tar: Options '-[0-7][lmh]' not supported by *this* tar Try 'tar --help' or 'tar --usage' for more information.
            – tli
            Feb 8 at 14:00










          • @tli Are you using -O (capital letter O), or -0 (number 0)? The capital letter O option is a GNU tar extension to extract to stdout.
            – Andrew Henle
            Feb 8 at 14:06











          • @AndrewHenle my bad, thanks for pointing that out, now it works!
            – tli
            Feb 8 at 14:12










          • The option is also supported on other platforms, e.g. FreeBSD.
            – Stephen Kitt
            Feb 8 at 14:13












          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          You can extract the file to standard output and redirect that:



          tar -xvf foo.tar.gz -O folder_1/folder_2/file.txt > file.txt


          (Note that the option is a capital “O”, not the digit “0”.)






          share|improve this answer














          You can extract the file to standard output and redirect that:



          tar -xvf foo.tar.gz -O folder_1/folder_2/file.txt > file.txt


          (Note that the option is a capital “O”, not the digit “0”.)







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 8 at 14:12

























          answered Feb 8 at 13:51









          Stephen Kitt

          142k22308369




          142k22308369











          • I am getting this printed out, and my file.txt gets extracted without any content: tar: Options '-[0-7][lmh]' not supported by *this* tar Try 'tar --help' or 'tar --usage' for more information.
            – tli
            Feb 8 at 14:00










          • @tli Are you using -O (capital letter O), or -0 (number 0)? The capital letter O option is a GNU tar extension to extract to stdout.
            – Andrew Henle
            Feb 8 at 14:06











          • @AndrewHenle my bad, thanks for pointing that out, now it works!
            – tli
            Feb 8 at 14:12










          • The option is also supported on other platforms, e.g. FreeBSD.
            – Stephen Kitt
            Feb 8 at 14:13
















          • I am getting this printed out, and my file.txt gets extracted without any content: tar: Options '-[0-7][lmh]' not supported by *this* tar Try 'tar --help' or 'tar --usage' for more information.
            – tli
            Feb 8 at 14:00










          • @tli Are you using -O (capital letter O), or -0 (number 0)? The capital letter O option is a GNU tar extension to extract to stdout.
            – Andrew Henle
            Feb 8 at 14:06











          • @AndrewHenle my bad, thanks for pointing that out, now it works!
            – tli
            Feb 8 at 14:12










          • The option is also supported on other platforms, e.g. FreeBSD.
            – Stephen Kitt
            Feb 8 at 14:13















          I am getting this printed out, and my file.txt gets extracted without any content: tar: Options '-[0-7][lmh]' not supported by *this* tar Try 'tar --help' or 'tar --usage' for more information.
          – tli
          Feb 8 at 14:00




          I am getting this printed out, and my file.txt gets extracted without any content: tar: Options '-[0-7][lmh]' not supported by *this* tar Try 'tar --help' or 'tar --usage' for more information.
          – tli
          Feb 8 at 14:00












          @tli Are you using -O (capital letter O), or -0 (number 0)? The capital letter O option is a GNU tar extension to extract to stdout.
          – Andrew Henle
          Feb 8 at 14:06





          @tli Are you using -O (capital letter O), or -0 (number 0)? The capital letter O option is a GNU tar extension to extract to stdout.
          – Andrew Henle
          Feb 8 at 14:06













          @AndrewHenle my bad, thanks for pointing that out, now it works!
          – tli
          Feb 8 at 14:12




          @AndrewHenle my bad, thanks for pointing that out, now it works!
          – tli
          Feb 8 at 14:12












          The option is also supported on other platforms, e.g. FreeBSD.
          – Stephen Kitt
          Feb 8 at 14:13




          The option is also supported on other platforms, e.g. FreeBSD.
          – Stephen Kitt
          Feb 8 at 14:13


          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay