With bsdtar “--exclude”, how to only exclude subdirectories?

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











up vote
2
down vote

favorite












In GNU tar (i.e. gtar), the --exclude option with a glob only matches the subdirectories, but not the directory itself. For example, --exclude test-tar/a/b/* would exclude anything inside of b, but not b itself. However, bsdtar is excluding the directory itself as well. My question is how do I make bsdtar act the same as GNU in this regard?



Here is an example script the demonstrates the problem:



#!/usr/bin/env bash

echo -e "nGiven an archive that looks like this:"
bsdtar -tf test.tgz

echo -e "nExtract the archive excluding test-tar/a/b/* using gtar"
rm -rf test-tar
gtar -xzf test.tgz --exclude 'test-tar/a/b/*'
file test-tar/a/b
file test-tar/a/b/B.txt

echo -e "nExtract the archive excluding test-tar/a/b/* using bsdtar"
rm -rf test-tar
bsdtar -xzf test.tgz --exclude 'test-tar/a/b/*'
file test-tar/a/b
file test-tar/a/b/B.txt


This outputs:



Given an archive that looks like this:
test-tar/
test-tar/a/
test-tar/a/A.txt
test-tar/a/b/
test-tar/a/b/B.txt

Extract the archive excluding test-tar/a/b/* using gtar
test-tar/a/b: directory
test-tar/a/b/B.txt: cannot open `test-tar/a/b/B.txt' (No such file or directory)

Extract the archive excluding test-tar/a/b/* using bsdtar
test-tar/a/b: cannot open `test-tar/a/b' (No such file or directory)
test-tar/a/b/B.txt: cannot open `test-tar/a/b/B.txt' (No such file or directory)


My versions are tar (GNU tar) 1.29 and bsdtar 3.3.2.







share|improve this question


























    up vote
    2
    down vote

    favorite












    In GNU tar (i.e. gtar), the --exclude option with a glob only matches the subdirectories, but not the directory itself. For example, --exclude test-tar/a/b/* would exclude anything inside of b, but not b itself. However, bsdtar is excluding the directory itself as well. My question is how do I make bsdtar act the same as GNU in this regard?



    Here is an example script the demonstrates the problem:



    #!/usr/bin/env bash

    echo -e "nGiven an archive that looks like this:"
    bsdtar -tf test.tgz

    echo -e "nExtract the archive excluding test-tar/a/b/* using gtar"
    rm -rf test-tar
    gtar -xzf test.tgz --exclude 'test-tar/a/b/*'
    file test-tar/a/b
    file test-tar/a/b/B.txt

    echo -e "nExtract the archive excluding test-tar/a/b/* using bsdtar"
    rm -rf test-tar
    bsdtar -xzf test.tgz --exclude 'test-tar/a/b/*'
    file test-tar/a/b
    file test-tar/a/b/B.txt


    This outputs:



    Given an archive that looks like this:
    test-tar/
    test-tar/a/
    test-tar/a/A.txt
    test-tar/a/b/
    test-tar/a/b/B.txt

    Extract the archive excluding test-tar/a/b/* using gtar
    test-tar/a/b: directory
    test-tar/a/b/B.txt: cannot open `test-tar/a/b/B.txt' (No such file or directory)

    Extract the archive excluding test-tar/a/b/* using bsdtar
    test-tar/a/b: cannot open `test-tar/a/b' (No such file or directory)
    test-tar/a/b/B.txt: cannot open `test-tar/a/b/B.txt' (No such file or directory)


    My versions are tar (GNU tar) 1.29 and bsdtar 3.3.2.







    share|improve this question
























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      In GNU tar (i.e. gtar), the --exclude option with a glob only matches the subdirectories, but not the directory itself. For example, --exclude test-tar/a/b/* would exclude anything inside of b, but not b itself. However, bsdtar is excluding the directory itself as well. My question is how do I make bsdtar act the same as GNU in this regard?



      Here is an example script the demonstrates the problem:



      #!/usr/bin/env bash

      echo -e "nGiven an archive that looks like this:"
      bsdtar -tf test.tgz

      echo -e "nExtract the archive excluding test-tar/a/b/* using gtar"
      rm -rf test-tar
      gtar -xzf test.tgz --exclude 'test-tar/a/b/*'
      file test-tar/a/b
      file test-tar/a/b/B.txt

      echo -e "nExtract the archive excluding test-tar/a/b/* using bsdtar"
      rm -rf test-tar
      bsdtar -xzf test.tgz --exclude 'test-tar/a/b/*'
      file test-tar/a/b
      file test-tar/a/b/B.txt


      This outputs:



      Given an archive that looks like this:
      test-tar/
      test-tar/a/
      test-tar/a/A.txt
      test-tar/a/b/
      test-tar/a/b/B.txt

      Extract the archive excluding test-tar/a/b/* using gtar
      test-tar/a/b: directory
      test-tar/a/b/B.txt: cannot open `test-tar/a/b/B.txt' (No such file or directory)

      Extract the archive excluding test-tar/a/b/* using bsdtar
      test-tar/a/b: cannot open `test-tar/a/b' (No such file or directory)
      test-tar/a/b/B.txt: cannot open `test-tar/a/b/B.txt' (No such file or directory)


      My versions are tar (GNU tar) 1.29 and bsdtar 3.3.2.







      share|improve this question














      In GNU tar (i.e. gtar), the --exclude option with a glob only matches the subdirectories, but not the directory itself. For example, --exclude test-tar/a/b/* would exclude anything inside of b, but not b itself. However, bsdtar is excluding the directory itself as well. My question is how do I make bsdtar act the same as GNU in this regard?



      Here is an example script the demonstrates the problem:



      #!/usr/bin/env bash

      echo -e "nGiven an archive that looks like this:"
      bsdtar -tf test.tgz

      echo -e "nExtract the archive excluding test-tar/a/b/* using gtar"
      rm -rf test-tar
      gtar -xzf test.tgz --exclude 'test-tar/a/b/*'
      file test-tar/a/b
      file test-tar/a/b/B.txt

      echo -e "nExtract the archive excluding test-tar/a/b/* using bsdtar"
      rm -rf test-tar
      bsdtar -xzf test.tgz --exclude 'test-tar/a/b/*'
      file test-tar/a/b
      file test-tar/a/b/B.txt


      This outputs:



      Given an archive that looks like this:
      test-tar/
      test-tar/a/
      test-tar/a/A.txt
      test-tar/a/b/
      test-tar/a/b/B.txt

      Extract the archive excluding test-tar/a/b/* using gtar
      test-tar/a/b: directory
      test-tar/a/b/B.txt: cannot open `test-tar/a/b/B.txt' (No such file or directory)

      Extract the archive excluding test-tar/a/b/* using bsdtar
      test-tar/a/b: cannot open `test-tar/a/b' (No such file or directory)
      test-tar/a/b/B.txt: cannot open `test-tar/a/b/B.txt' (No such file or directory)


      My versions are tar (GNU tar) 1.29 and bsdtar 3.3.2.









      share|improve this question













      share|improve this question




      share|improve this question








      edited Jul 24 at 16:23









      Volker Siegel

      10.2k33058




      10.2k33058










      asked Nov 29 '17 at 8:45









      ryanbrainard

      1264




      1264

























          active

          oldest

          votes











          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%2f407679%2fwith-bsdtar-exclude-how-to-only-exclude-subdirectories%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f407679%2fwith-bsdtar-exclude-how-to-only-exclude-subdirectories%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?

          Displaying single band from multi-band raster using QGIS

          How many registers does an x86_64 CPU actually have?