Exclude files except a specific on in tar

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











up vote
0
down vote

favorite












I want to make a tarball of a directory, but excluding all files that end with .foo, except for one specific file. This excludes all files with .foo as ending:



tar czf "$nameTarball" dir/ --exclude '*.foo'


What I'm missing is some sort of --include option. Does it exist?
I'm using GNU tar 1.23.










share|improve this question



























    up vote
    0
    down vote

    favorite












    I want to make a tarball of a directory, but excluding all files that end with .foo, except for one specific file. This excludes all files with .foo as ending:



    tar czf "$nameTarball" dir/ --exclude '*.foo'


    What I'm missing is some sort of --include option. Does it exist?
    I'm using GNU tar 1.23.










    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I want to make a tarball of a directory, but excluding all files that end with .foo, except for one specific file. This excludes all files with .foo as ending:



      tar czf "$nameTarball" dir/ --exclude '*.foo'


      What I'm missing is some sort of --include option. Does it exist?
      I'm using GNU tar 1.23.










      share|improve this question















      I want to make a tarball of a directory, but excluding all files that end with .foo, except for one specific file. This excludes all files with .foo as ending:



      tar czf "$nameTarball" dir/ --exclude '*.foo'


      What I'm missing is some sort of --include option. Does it exist?
      I'm using GNU tar 1.23.







      tar






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 31 at 14:24









      Jeff Schaller

      32.8k849110




      32.8k849110










      asked Aug 31 at 12:23









      pfnuesel

      2,60541838




      2,60541838




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          There is no --include-style option in GNU tar as far as I’m aware.



          In GNU tar, later versions (starting with 1.29) treat --exclude and other filename-selection options in a position-sensitive fashion, so they only affects arguments after them on the command line. So you can include files by naming them before the --exclude option:



          tar czf "$nameTarball" dir/specific.foo --exclude '*.foo' dir/





          share|improve this answer






















          • I installed a newer version of tar and it works now. Thanks! (I wonder why certain distros use tar that is from 2010!)
            – pfnuesel
            Aug 31 at 13:34










          • A typical tar implementation that is part of an operating system distro supports -I. This has been added to BSD tar (not bsdtar) in the late 1980s. But If a filename is in the -X file as well, itis excluded. Note that --exclude is a non-portable vendor unique GNU tar extension.
            – schily
            Aug 31 at 13:59










          • @schily GNU tar supports both -T (equivalent to BSD’s -I, where -T also works) and -X, but as you imply they’re not helpful in this situation since the exclusions given by -X have greater precedence than the files given by -T.
            – Stephen Kitt
            Aug 31 at 14:31










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f466023%2fexclude-files-except-a-specific-on-in-tar%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          There is no --include-style option in GNU tar as far as I’m aware.



          In GNU tar, later versions (starting with 1.29) treat --exclude and other filename-selection options in a position-sensitive fashion, so they only affects arguments after them on the command line. So you can include files by naming them before the --exclude option:



          tar czf "$nameTarball" dir/specific.foo --exclude '*.foo' dir/





          share|improve this answer






















          • I installed a newer version of tar and it works now. Thanks! (I wonder why certain distros use tar that is from 2010!)
            – pfnuesel
            Aug 31 at 13:34










          • A typical tar implementation that is part of an operating system distro supports -I. This has been added to BSD tar (not bsdtar) in the late 1980s. But If a filename is in the -X file as well, itis excluded. Note that --exclude is a non-portable vendor unique GNU tar extension.
            – schily
            Aug 31 at 13:59










          • @schily GNU tar supports both -T (equivalent to BSD’s -I, where -T also works) and -X, but as you imply they’re not helpful in this situation since the exclusions given by -X have greater precedence than the files given by -T.
            – Stephen Kitt
            Aug 31 at 14:31














          up vote
          1
          down vote



          accepted










          There is no --include-style option in GNU tar as far as I’m aware.



          In GNU tar, later versions (starting with 1.29) treat --exclude and other filename-selection options in a position-sensitive fashion, so they only affects arguments after them on the command line. So you can include files by naming them before the --exclude option:



          tar czf "$nameTarball" dir/specific.foo --exclude '*.foo' dir/





          share|improve this answer






















          • I installed a newer version of tar and it works now. Thanks! (I wonder why certain distros use tar that is from 2010!)
            – pfnuesel
            Aug 31 at 13:34










          • A typical tar implementation that is part of an operating system distro supports -I. This has been added to BSD tar (not bsdtar) in the late 1980s. But If a filename is in the -X file as well, itis excluded. Note that --exclude is a non-portable vendor unique GNU tar extension.
            – schily
            Aug 31 at 13:59










          • @schily GNU tar supports both -T (equivalent to BSD’s -I, where -T also works) and -X, but as you imply they’re not helpful in this situation since the exclusions given by -X have greater precedence than the files given by -T.
            – Stephen Kitt
            Aug 31 at 14:31












          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          There is no --include-style option in GNU tar as far as I’m aware.



          In GNU tar, later versions (starting with 1.29) treat --exclude and other filename-selection options in a position-sensitive fashion, so they only affects arguments after them on the command line. So you can include files by naming them before the --exclude option:



          tar czf "$nameTarball" dir/specific.foo --exclude '*.foo' dir/





          share|improve this answer














          There is no --include-style option in GNU tar as far as I’m aware.



          In GNU tar, later versions (starting with 1.29) treat --exclude and other filename-selection options in a position-sensitive fashion, so they only affects arguments after them on the command line. So you can include files by naming them before the --exclude option:



          tar czf "$nameTarball" dir/specific.foo --exclude '*.foo' dir/






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Aug 31 at 14:29

























          answered Aug 31 at 12:41









          Stephen Kitt

          147k22321388




          147k22321388











          • I installed a newer version of tar and it works now. Thanks! (I wonder why certain distros use tar that is from 2010!)
            – pfnuesel
            Aug 31 at 13:34










          • A typical tar implementation that is part of an operating system distro supports -I. This has been added to BSD tar (not bsdtar) in the late 1980s. But If a filename is in the -X file as well, itis excluded. Note that --exclude is a non-portable vendor unique GNU tar extension.
            – schily
            Aug 31 at 13:59










          • @schily GNU tar supports both -T (equivalent to BSD’s -I, where -T also works) and -X, but as you imply they’re not helpful in this situation since the exclusions given by -X have greater precedence than the files given by -T.
            – Stephen Kitt
            Aug 31 at 14:31
















          • I installed a newer version of tar and it works now. Thanks! (I wonder why certain distros use tar that is from 2010!)
            – pfnuesel
            Aug 31 at 13:34










          • A typical tar implementation that is part of an operating system distro supports -I. This has been added to BSD tar (not bsdtar) in the late 1980s. But If a filename is in the -X file as well, itis excluded. Note that --exclude is a non-portable vendor unique GNU tar extension.
            – schily
            Aug 31 at 13:59










          • @schily GNU tar supports both -T (equivalent to BSD’s -I, where -T also works) and -X, but as you imply they’re not helpful in this situation since the exclusions given by -X have greater precedence than the files given by -T.
            – Stephen Kitt
            Aug 31 at 14:31















          I installed a newer version of tar and it works now. Thanks! (I wonder why certain distros use tar that is from 2010!)
          – pfnuesel
          Aug 31 at 13:34




          I installed a newer version of tar and it works now. Thanks! (I wonder why certain distros use tar that is from 2010!)
          – pfnuesel
          Aug 31 at 13:34












          A typical tar implementation that is part of an operating system distro supports -I. This has been added to BSD tar (not bsdtar) in the late 1980s. But If a filename is in the -X file as well, itis excluded. Note that --exclude is a non-portable vendor unique GNU tar extension.
          – schily
          Aug 31 at 13:59




          A typical tar implementation that is part of an operating system distro supports -I. This has been added to BSD tar (not bsdtar) in the late 1980s. But If a filename is in the -X file as well, itis excluded. Note that --exclude is a non-portable vendor unique GNU tar extension.
          – schily
          Aug 31 at 13:59












          @schily GNU tar supports both -T (equivalent to BSD’s -I, where -T also works) and -X, but as you imply they’re not helpful in this situation since the exclusions given by -X have greater precedence than the files given by -T.
          – Stephen Kitt
          Aug 31 at 14:31




          @schily GNU tar supports both -T (equivalent to BSD’s -I, where -T also works) and -X, but as you imply they’re not helpful in this situation since the exclusions given by -X have greater precedence than the files given by -T.
          – Stephen Kitt
          Aug 31 at 14:31

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f466023%2fexclude-files-except-a-specific-on-in-tar%23new-answer', 'question_page');

          );

          Post as a guest













































































          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