Portable way to invoke tar with a list of files from stdin












2














I want to create a .tgz from the content of a directory. I also want to strip the leading "./" from the tar'ed content.

I had done this as follows:



cd /path/to/files/ && find . -type f | cut -c 3- | xargs czf /path/to/tgz/myTgz.tgz


I learned recently that using xargs may not be the best way to pull this off because xargs may invoke tar multiple times if the cmdline arg list gets too long, and I was advised to make use of tar's ability to read a list of input files from stdin. I ended up finding this article on how to do this. However, I find that the recommendation...



cd /path/to/files/ && find . -type f | cut -c 3- | tar czf foo.tgz -T -


...seems to not be portable. It runs fine on my dev PC, but on a busybox target, I get the following error from running the same command:



tar: can't open '-': No such file or directory


So, my question: is there a truly portable/global way to invoke tar to create a .tgz by feeding it input files from stdin (as opposed to cmdline arguments)?



(It is not an option available to me to install alternatives to tar such as gnutar/bsdtar/etc.)



(Secondary question: Why does the "-T -" argument to tar denote "read files from stdin"? From the tar man page, all I could find was that "-T" means:




get names to extract or create from FILE




... but I couldn't see any reference to a plain "-")










share|improve this question




















  • 3




    See Usage of dash (-) in place of a filename.
    – Michael Homer
    1 hour ago






  • 2




    Since tar is not a POSIX utility, a truly portable (as in "standard") implementation may not be found. pax, on the other hand, is a POSIX utility.
    – Kusalananda
    1 hour ago










  • This site does one question per question, and that tertiary question is a massive distraction that is a question in its own right, most likely already long since covered.
    – JdeBP
    1 hour ago










  • @JdeBP - removed tertiary question
    – StoneThrow
    1 hour ago










  • @Kusalananda - that's an informative comment; thank you. However, it looks like pax isn't available in Busybox (at least in the version of Busybox I have to work with). I think I may have to resign myself to using the sub-optimal approach using xargs.
    – StoneThrow
    1 hour ago
















2














I want to create a .tgz from the content of a directory. I also want to strip the leading "./" from the tar'ed content.

I had done this as follows:



cd /path/to/files/ && find . -type f | cut -c 3- | xargs czf /path/to/tgz/myTgz.tgz


I learned recently that using xargs may not be the best way to pull this off because xargs may invoke tar multiple times if the cmdline arg list gets too long, and I was advised to make use of tar's ability to read a list of input files from stdin. I ended up finding this article on how to do this. However, I find that the recommendation...



cd /path/to/files/ && find . -type f | cut -c 3- | tar czf foo.tgz -T -


...seems to not be portable. It runs fine on my dev PC, but on a busybox target, I get the following error from running the same command:



tar: can't open '-': No such file or directory


So, my question: is there a truly portable/global way to invoke tar to create a .tgz by feeding it input files from stdin (as opposed to cmdline arguments)?



(It is not an option available to me to install alternatives to tar such as gnutar/bsdtar/etc.)



(Secondary question: Why does the "-T -" argument to tar denote "read files from stdin"? From the tar man page, all I could find was that "-T" means:




get names to extract or create from FILE




... but I couldn't see any reference to a plain "-")










share|improve this question




















  • 3




    See Usage of dash (-) in place of a filename.
    – Michael Homer
    1 hour ago






  • 2




    Since tar is not a POSIX utility, a truly portable (as in "standard") implementation may not be found. pax, on the other hand, is a POSIX utility.
    – Kusalananda
    1 hour ago










  • This site does one question per question, and that tertiary question is a massive distraction that is a question in its own right, most likely already long since covered.
    – JdeBP
    1 hour ago










  • @JdeBP - removed tertiary question
    – StoneThrow
    1 hour ago










  • @Kusalananda - that's an informative comment; thank you. However, it looks like pax isn't available in Busybox (at least in the version of Busybox I have to work with). I think I may have to resign myself to using the sub-optimal approach using xargs.
    – StoneThrow
    1 hour ago














2












2








2







I want to create a .tgz from the content of a directory. I also want to strip the leading "./" from the tar'ed content.

I had done this as follows:



cd /path/to/files/ && find . -type f | cut -c 3- | xargs czf /path/to/tgz/myTgz.tgz


I learned recently that using xargs may not be the best way to pull this off because xargs may invoke tar multiple times if the cmdline arg list gets too long, and I was advised to make use of tar's ability to read a list of input files from stdin. I ended up finding this article on how to do this. However, I find that the recommendation...



cd /path/to/files/ && find . -type f | cut -c 3- | tar czf foo.tgz -T -


...seems to not be portable. It runs fine on my dev PC, but on a busybox target, I get the following error from running the same command:



tar: can't open '-': No such file or directory


So, my question: is there a truly portable/global way to invoke tar to create a .tgz by feeding it input files from stdin (as opposed to cmdline arguments)?



(It is not an option available to me to install alternatives to tar such as gnutar/bsdtar/etc.)



(Secondary question: Why does the "-T -" argument to tar denote "read files from stdin"? From the tar man page, all I could find was that "-T" means:




get names to extract or create from FILE




... but I couldn't see any reference to a plain "-")










share|improve this question















I want to create a .tgz from the content of a directory. I also want to strip the leading "./" from the tar'ed content.

I had done this as follows:



cd /path/to/files/ && find . -type f | cut -c 3- | xargs czf /path/to/tgz/myTgz.tgz


I learned recently that using xargs may not be the best way to pull this off because xargs may invoke tar multiple times if the cmdline arg list gets too long, and I was advised to make use of tar's ability to read a list of input files from stdin. I ended up finding this article on how to do this. However, I find that the recommendation...



cd /path/to/files/ && find . -type f | cut -c 3- | tar czf foo.tgz -T -


...seems to not be portable. It runs fine on my dev PC, but on a busybox target, I get the following error from running the same command:



tar: can't open '-': No such file or directory


So, my question: is there a truly portable/global way to invoke tar to create a .tgz by feeding it input files from stdin (as opposed to cmdline arguments)?



(It is not an option available to me to install alternatives to tar such as gnutar/bsdtar/etc.)



(Secondary question: Why does the "-T -" argument to tar denote "read files from stdin"? From the tar man page, all I could find was that "-T" means:




get names to extract or create from FILE




... but I couldn't see any reference to a plain "-")







io-redirection tar busybox stdin options






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 1 hour ago









Gilles

529k12810601585




529k12810601585










asked 1 hour ago









StoneThrow

432413




432413








  • 3




    See Usage of dash (-) in place of a filename.
    – Michael Homer
    1 hour ago






  • 2




    Since tar is not a POSIX utility, a truly portable (as in "standard") implementation may not be found. pax, on the other hand, is a POSIX utility.
    – Kusalananda
    1 hour ago










  • This site does one question per question, and that tertiary question is a massive distraction that is a question in its own right, most likely already long since covered.
    – JdeBP
    1 hour ago










  • @JdeBP - removed tertiary question
    – StoneThrow
    1 hour ago










  • @Kusalananda - that's an informative comment; thank you. However, it looks like pax isn't available in Busybox (at least in the version of Busybox I have to work with). I think I may have to resign myself to using the sub-optimal approach using xargs.
    – StoneThrow
    1 hour ago














  • 3




    See Usage of dash (-) in place of a filename.
    – Michael Homer
    1 hour ago






  • 2




    Since tar is not a POSIX utility, a truly portable (as in "standard") implementation may not be found. pax, on the other hand, is a POSIX utility.
    – Kusalananda
    1 hour ago










  • This site does one question per question, and that tertiary question is a massive distraction that is a question in its own right, most likely already long since covered.
    – JdeBP
    1 hour ago










  • @JdeBP - removed tertiary question
    – StoneThrow
    1 hour ago










  • @Kusalananda - that's an informative comment; thank you. However, it looks like pax isn't available in Busybox (at least in the version of Busybox I have to work with). I think I may have to resign myself to using the sub-optimal approach using xargs.
    – StoneThrow
    1 hour ago








3




3




See Usage of dash (-) in place of a filename.
– Michael Homer
1 hour ago




See Usage of dash (-) in place of a filename.
– Michael Homer
1 hour ago




2




2




Since tar is not a POSIX utility, a truly portable (as in "standard") implementation may not be found. pax, on the other hand, is a POSIX utility.
– Kusalananda
1 hour ago




Since tar is not a POSIX utility, a truly portable (as in "standard") implementation may not be found. pax, on the other hand, is a POSIX utility.
– Kusalananda
1 hour ago












This site does one question per question, and that tertiary question is a massive distraction that is a question in its own right, most likely already long since covered.
– JdeBP
1 hour ago




This site does one question per question, and that tertiary question is a massive distraction that is a question in its own right, most likely already long since covered.
– JdeBP
1 hour ago












@JdeBP - removed tertiary question
– StoneThrow
1 hour ago




@JdeBP - removed tertiary question
– StoneThrow
1 hour ago












@Kusalananda - that's an informative comment; thank you. However, it looks like pax isn't available in Busybox (at least in the version of Busybox I have to work with). I think I may have to resign myself to using the sub-optimal approach using xargs.
– StoneThrow
1 hour ago




@Kusalananda - that's an informative comment; thank you. However, it looks like pax isn't available in Busybox (at least in the version of Busybox I have to work with). I think I may have to resign myself to using the sub-optimal approach using xargs.
– StoneThrow
1 hour ago










3 Answers
3






active

oldest

votes


















2














I know that is a stupid answer and maybe not good for you but how bad is if you just...



cd /path/to/files/ && find . -type f | cut -c 3- >/tmp/temp.txt 
tar czf foo.tgz -T /tmp/temp.txt





share|improve this answer





















  • Not at all a stupid answer. The original question (and the reason why I asked if this was possible to do this from stdin) was because of the problem I noted RE: xargs calling tar multiple times if the input list is too long...does this solution also bypass that problem? (it seems like it does because it's also using "-T", not explicitly putting the source files as command-line arguments)
    – StoneThrow
    37 mins ago



















2














It is a common convention to interpret - to mean standard input where an input file name is expected, and to mean standard output where an output file name is expected. Because this is a common convention, the short help summary in the GNU tar man page does not mention it, but the complete manual (usually available locally through info tar) does. The POSIX command line utility syntax guidelines includes this convention, so it's pretty widespread (but it's always a choice on the part of the author of the program).



BusyBox utilities do follow this convention. But the manual does not mention tar as supporting the option -T, and neither does the version on the machine I'm posting this (1.27.2 on Ubuntu). I don't know why you're getting the error “: No such file or directory” rather than “invalid option -- 'T'”. It seems that your tar interprets -T as an option that does not take an argument, then sees - as a file name. Since in this context tar needs a file name to put in the archive, and not just some content that comes from a file, it would not make sense to use the stdin/stdout interpretation for -.



BusyBox utilities support a restricted set of functionality by design, because they're intended for embedded systems where the fancier features of GNU utilities wouldn't fit. Apparently -T is not a feature that the BusyBox designers considered useful.



I don't think BusyBox tar has any way to read file names from stdin. If you need to archive a subset of the files in a directory and you don't need any symbolic links in the archive, a workaround is to create a forest of symbolic links in a temporary directory and archive this temporary directory.



It's not clear exactly why you're using find. If you only want the files in the current directory, why not tar czf /path/to/archive.tgz -- * ? Your command does make sense if there are subdirectories and you want to archive the files in these subdirectories, but not the directories themselves (presumably to restore them in a place where the directory structure must exist but may have different permissions). In this case a leading ./ wouldn't do any harm.






share|improve this answer





























    1














    You can use the -u/--update option in conjunction with xargs.
    I just tried and to prove that it works, I gave the filename arguments to tar one-by-one using xargs -n 1:



    find top_of_tree/ -type f | xargs -n 1 tar -uf archive.tar



    Of course, this is just a proof of concept. In your case, it is probably more practical to allow xargs to separate the argument list into larger parts that do not exceed the argument length limit, so as to avoid having a lot of calls to tar:



    find top_of_tree/ -type f | xargs tar -uf archive.tar



    The prerequisite is that all implementations of tar on your platforms support at least one of the -u/--update flags.



    EDIT: the -u/--update flags allow tar to create as well as append to an archive.



    I just noticed that unfortunately, you cannot update compressed archives (tgz, created with the -c flag). However, you can, by all means create a non-compressed archive first and then compress the results.



    Also, it should not confuse you that I'm using flags to tar with a hyphen ('-' character). It accepts both forms. In my example, -uf would be equivalent to uf in yours.



    As for the - option, it is probalby not documented in the man page of tar because it is a very common Unix convention for command line tools that deal with streams as well as named files.
    - us usually a special argument for filters and names the standard input stream as a file.



    EDIT: As Gilles wrote in their very informative answer, which they have however now removed, - is also used to name the standard error stream.
    It depends on which one can be unambiguously assumed. Usually, only one of them makes sense, since the other is specified in some other way.






    share|improve this answer























    • Good idea, thank you, but unfortunately, looks like Busybox version of tar does not support -u/-update.
      – StoneThrow
      35 mins ago










    • I worked a lot on embedded machines with BusyBox as well. Unfortunately, my only solution was to cross-compile 7Zip for that system.
      – Larry
      28 mins ago










    • -u wouldn't work with a gzipped archive anyway.
      – Gilles
      22 mins ago











    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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    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%2f492308%2fportable-way-to-invoke-tar-with-a-list-of-files-from-stdin%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    I know that is a stupid answer and maybe not good for you but how bad is if you just...



    cd /path/to/files/ && find . -type f | cut -c 3- >/tmp/temp.txt 
    tar czf foo.tgz -T /tmp/temp.txt





    share|improve this answer





















    • Not at all a stupid answer. The original question (and the reason why I asked if this was possible to do this from stdin) was because of the problem I noted RE: xargs calling tar multiple times if the input list is too long...does this solution also bypass that problem? (it seems like it does because it's also using "-T", not explicitly putting the source files as command-line arguments)
      – StoneThrow
      37 mins ago
















    2














    I know that is a stupid answer and maybe not good for you but how bad is if you just...



    cd /path/to/files/ && find . -type f | cut -c 3- >/tmp/temp.txt 
    tar czf foo.tgz -T /tmp/temp.txt





    share|improve this answer





















    • Not at all a stupid answer. The original question (and the reason why I asked if this was possible to do this from stdin) was because of the problem I noted RE: xargs calling tar multiple times if the input list is too long...does this solution also bypass that problem? (it seems like it does because it's also using "-T", not explicitly putting the source files as command-line arguments)
      – StoneThrow
      37 mins ago














    2












    2








    2






    I know that is a stupid answer and maybe not good for you but how bad is if you just...



    cd /path/to/files/ && find . -type f | cut -c 3- >/tmp/temp.txt 
    tar czf foo.tgz -T /tmp/temp.txt





    share|improve this answer












    I know that is a stupid answer and maybe not good for you but how bad is if you just...



    cd /path/to/files/ && find . -type f | cut -c 3- >/tmp/temp.txt 
    tar czf foo.tgz -T /tmp/temp.txt






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered 54 mins ago









    Luciano Andress Martini

    3,513931




    3,513931












    • Not at all a stupid answer. The original question (and the reason why I asked if this was possible to do this from stdin) was because of the problem I noted RE: xargs calling tar multiple times if the input list is too long...does this solution also bypass that problem? (it seems like it does because it's also using "-T", not explicitly putting the source files as command-line arguments)
      – StoneThrow
      37 mins ago


















    • Not at all a stupid answer. The original question (and the reason why I asked if this was possible to do this from stdin) was because of the problem I noted RE: xargs calling tar multiple times if the input list is too long...does this solution also bypass that problem? (it seems like it does because it's also using "-T", not explicitly putting the source files as command-line arguments)
      – StoneThrow
      37 mins ago
















    Not at all a stupid answer. The original question (and the reason why I asked if this was possible to do this from stdin) was because of the problem I noted RE: xargs calling tar multiple times if the input list is too long...does this solution also bypass that problem? (it seems like it does because it's also using "-T", not explicitly putting the source files as command-line arguments)
    – StoneThrow
    37 mins ago




    Not at all a stupid answer. The original question (and the reason why I asked if this was possible to do this from stdin) was because of the problem I noted RE: xargs calling tar multiple times if the input list is too long...does this solution also bypass that problem? (it seems like it does because it's also using "-T", not explicitly putting the source files as command-line arguments)
    – StoneThrow
    37 mins ago













    2














    It is a common convention to interpret - to mean standard input where an input file name is expected, and to mean standard output where an output file name is expected. Because this is a common convention, the short help summary in the GNU tar man page does not mention it, but the complete manual (usually available locally through info tar) does. The POSIX command line utility syntax guidelines includes this convention, so it's pretty widespread (but it's always a choice on the part of the author of the program).



    BusyBox utilities do follow this convention. But the manual does not mention tar as supporting the option -T, and neither does the version on the machine I'm posting this (1.27.2 on Ubuntu). I don't know why you're getting the error “: No such file or directory” rather than “invalid option -- 'T'”. It seems that your tar interprets -T as an option that does not take an argument, then sees - as a file name. Since in this context tar needs a file name to put in the archive, and not just some content that comes from a file, it would not make sense to use the stdin/stdout interpretation for -.



    BusyBox utilities support a restricted set of functionality by design, because they're intended for embedded systems where the fancier features of GNU utilities wouldn't fit. Apparently -T is not a feature that the BusyBox designers considered useful.



    I don't think BusyBox tar has any way to read file names from stdin. If you need to archive a subset of the files in a directory and you don't need any symbolic links in the archive, a workaround is to create a forest of symbolic links in a temporary directory and archive this temporary directory.



    It's not clear exactly why you're using find. If you only want the files in the current directory, why not tar czf /path/to/archive.tgz -- * ? Your command does make sense if there are subdirectories and you want to archive the files in these subdirectories, but not the directories themselves (presumably to restore them in a place where the directory structure must exist but may have different permissions). In this case a leading ./ wouldn't do any harm.






    share|improve this answer


























      2














      It is a common convention to interpret - to mean standard input where an input file name is expected, and to mean standard output where an output file name is expected. Because this is a common convention, the short help summary in the GNU tar man page does not mention it, but the complete manual (usually available locally through info tar) does. The POSIX command line utility syntax guidelines includes this convention, so it's pretty widespread (but it's always a choice on the part of the author of the program).



      BusyBox utilities do follow this convention. But the manual does not mention tar as supporting the option -T, and neither does the version on the machine I'm posting this (1.27.2 on Ubuntu). I don't know why you're getting the error “: No such file or directory” rather than “invalid option -- 'T'”. It seems that your tar interprets -T as an option that does not take an argument, then sees - as a file name. Since in this context tar needs a file name to put in the archive, and not just some content that comes from a file, it would not make sense to use the stdin/stdout interpretation for -.



      BusyBox utilities support a restricted set of functionality by design, because they're intended for embedded systems where the fancier features of GNU utilities wouldn't fit. Apparently -T is not a feature that the BusyBox designers considered useful.



      I don't think BusyBox tar has any way to read file names from stdin. If you need to archive a subset of the files in a directory and you don't need any symbolic links in the archive, a workaround is to create a forest of symbolic links in a temporary directory and archive this temporary directory.



      It's not clear exactly why you're using find. If you only want the files in the current directory, why not tar czf /path/to/archive.tgz -- * ? Your command does make sense if there are subdirectories and you want to archive the files in these subdirectories, but not the directories themselves (presumably to restore them in a place where the directory structure must exist but may have different permissions). In this case a leading ./ wouldn't do any harm.






      share|improve this answer
























        2












        2








        2






        It is a common convention to interpret - to mean standard input where an input file name is expected, and to mean standard output where an output file name is expected. Because this is a common convention, the short help summary in the GNU tar man page does not mention it, but the complete manual (usually available locally through info tar) does. The POSIX command line utility syntax guidelines includes this convention, so it's pretty widespread (but it's always a choice on the part of the author of the program).



        BusyBox utilities do follow this convention. But the manual does not mention tar as supporting the option -T, and neither does the version on the machine I'm posting this (1.27.2 on Ubuntu). I don't know why you're getting the error “: No such file or directory” rather than “invalid option -- 'T'”. It seems that your tar interprets -T as an option that does not take an argument, then sees - as a file name. Since in this context tar needs a file name to put in the archive, and not just some content that comes from a file, it would not make sense to use the stdin/stdout interpretation for -.



        BusyBox utilities support a restricted set of functionality by design, because they're intended for embedded systems where the fancier features of GNU utilities wouldn't fit. Apparently -T is not a feature that the BusyBox designers considered useful.



        I don't think BusyBox tar has any way to read file names from stdin. If you need to archive a subset of the files in a directory and you don't need any symbolic links in the archive, a workaround is to create a forest of symbolic links in a temporary directory and archive this temporary directory.



        It's not clear exactly why you're using find. If you only want the files in the current directory, why not tar czf /path/to/archive.tgz -- * ? Your command does make sense if there are subdirectories and you want to archive the files in these subdirectories, but not the directories themselves (presumably to restore them in a place where the directory structure must exist but may have different permissions). In this case a leading ./ wouldn't do any harm.






        share|improve this answer












        It is a common convention to interpret - to mean standard input where an input file name is expected, and to mean standard output where an output file name is expected. Because this is a common convention, the short help summary in the GNU tar man page does not mention it, but the complete manual (usually available locally through info tar) does. The POSIX command line utility syntax guidelines includes this convention, so it's pretty widespread (but it's always a choice on the part of the author of the program).



        BusyBox utilities do follow this convention. But the manual does not mention tar as supporting the option -T, and neither does the version on the machine I'm posting this (1.27.2 on Ubuntu). I don't know why you're getting the error “: No such file or directory” rather than “invalid option -- 'T'”. It seems that your tar interprets -T as an option that does not take an argument, then sees - as a file name. Since in this context tar needs a file name to put in the archive, and not just some content that comes from a file, it would not make sense to use the stdin/stdout interpretation for -.



        BusyBox utilities support a restricted set of functionality by design, because they're intended for embedded systems where the fancier features of GNU utilities wouldn't fit. Apparently -T is not a feature that the BusyBox designers considered useful.



        I don't think BusyBox tar has any way to read file names from stdin. If you need to archive a subset of the files in a directory and you don't need any symbolic links in the archive, a workaround is to create a forest of symbolic links in a temporary directory and archive this temporary directory.



        It's not clear exactly why you're using find. If you only want the files in the current directory, why not tar czf /path/to/archive.tgz -- * ? Your command does make sense if there are subdirectories and you want to archive the files in these subdirectories, but not the directories themselves (presumably to restore them in a place where the directory structure must exist but may have different permissions). In this case a leading ./ wouldn't do any harm.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 24 mins ago









        Gilles

        529k12810601585




        529k12810601585























            1














            You can use the -u/--update option in conjunction with xargs.
            I just tried and to prove that it works, I gave the filename arguments to tar one-by-one using xargs -n 1:



            find top_of_tree/ -type f | xargs -n 1 tar -uf archive.tar



            Of course, this is just a proof of concept. In your case, it is probably more practical to allow xargs to separate the argument list into larger parts that do not exceed the argument length limit, so as to avoid having a lot of calls to tar:



            find top_of_tree/ -type f | xargs tar -uf archive.tar



            The prerequisite is that all implementations of tar on your platforms support at least one of the -u/--update flags.



            EDIT: the -u/--update flags allow tar to create as well as append to an archive.



            I just noticed that unfortunately, you cannot update compressed archives (tgz, created with the -c flag). However, you can, by all means create a non-compressed archive first and then compress the results.



            Also, it should not confuse you that I'm using flags to tar with a hyphen ('-' character). It accepts both forms. In my example, -uf would be equivalent to uf in yours.



            As for the - option, it is probalby not documented in the man page of tar because it is a very common Unix convention for command line tools that deal with streams as well as named files.
            - us usually a special argument for filters and names the standard input stream as a file.



            EDIT: As Gilles wrote in their very informative answer, which they have however now removed, - is also used to name the standard error stream.
            It depends on which one can be unambiguously assumed. Usually, only one of them makes sense, since the other is specified in some other way.






            share|improve this answer























            • Good idea, thank you, but unfortunately, looks like Busybox version of tar does not support -u/-update.
              – StoneThrow
              35 mins ago










            • I worked a lot on embedded machines with BusyBox as well. Unfortunately, my only solution was to cross-compile 7Zip for that system.
              – Larry
              28 mins ago










            • -u wouldn't work with a gzipped archive anyway.
              – Gilles
              22 mins ago
















            1














            You can use the -u/--update option in conjunction with xargs.
            I just tried and to prove that it works, I gave the filename arguments to tar one-by-one using xargs -n 1:



            find top_of_tree/ -type f | xargs -n 1 tar -uf archive.tar



            Of course, this is just a proof of concept. In your case, it is probably more practical to allow xargs to separate the argument list into larger parts that do not exceed the argument length limit, so as to avoid having a lot of calls to tar:



            find top_of_tree/ -type f | xargs tar -uf archive.tar



            The prerequisite is that all implementations of tar on your platforms support at least one of the -u/--update flags.



            EDIT: the -u/--update flags allow tar to create as well as append to an archive.



            I just noticed that unfortunately, you cannot update compressed archives (tgz, created with the -c flag). However, you can, by all means create a non-compressed archive first and then compress the results.



            Also, it should not confuse you that I'm using flags to tar with a hyphen ('-' character). It accepts both forms. In my example, -uf would be equivalent to uf in yours.



            As for the - option, it is probalby not documented in the man page of tar because it is a very common Unix convention for command line tools that deal with streams as well as named files.
            - us usually a special argument for filters and names the standard input stream as a file.



            EDIT: As Gilles wrote in their very informative answer, which they have however now removed, - is also used to name the standard error stream.
            It depends on which one can be unambiguously assumed. Usually, only one of them makes sense, since the other is specified in some other way.






            share|improve this answer























            • Good idea, thank you, but unfortunately, looks like Busybox version of tar does not support -u/-update.
              – StoneThrow
              35 mins ago










            • I worked a lot on embedded machines with BusyBox as well. Unfortunately, my only solution was to cross-compile 7Zip for that system.
              – Larry
              28 mins ago










            • -u wouldn't work with a gzipped archive anyway.
              – Gilles
              22 mins ago














            1












            1








            1






            You can use the -u/--update option in conjunction with xargs.
            I just tried and to prove that it works, I gave the filename arguments to tar one-by-one using xargs -n 1:



            find top_of_tree/ -type f | xargs -n 1 tar -uf archive.tar



            Of course, this is just a proof of concept. In your case, it is probably more practical to allow xargs to separate the argument list into larger parts that do not exceed the argument length limit, so as to avoid having a lot of calls to tar:



            find top_of_tree/ -type f | xargs tar -uf archive.tar



            The prerequisite is that all implementations of tar on your platforms support at least one of the -u/--update flags.



            EDIT: the -u/--update flags allow tar to create as well as append to an archive.



            I just noticed that unfortunately, you cannot update compressed archives (tgz, created with the -c flag). However, you can, by all means create a non-compressed archive first and then compress the results.



            Also, it should not confuse you that I'm using flags to tar with a hyphen ('-' character). It accepts both forms. In my example, -uf would be equivalent to uf in yours.



            As for the - option, it is probalby not documented in the man page of tar because it is a very common Unix convention for command line tools that deal with streams as well as named files.
            - us usually a special argument for filters and names the standard input stream as a file.



            EDIT: As Gilles wrote in their very informative answer, which they have however now removed, - is also used to name the standard error stream.
            It depends on which one can be unambiguously assumed. Usually, only one of them makes sense, since the other is specified in some other way.






            share|improve this answer














            You can use the -u/--update option in conjunction with xargs.
            I just tried and to prove that it works, I gave the filename arguments to tar one-by-one using xargs -n 1:



            find top_of_tree/ -type f | xargs -n 1 tar -uf archive.tar



            Of course, this is just a proof of concept. In your case, it is probably more practical to allow xargs to separate the argument list into larger parts that do not exceed the argument length limit, so as to avoid having a lot of calls to tar:



            find top_of_tree/ -type f | xargs tar -uf archive.tar



            The prerequisite is that all implementations of tar on your platforms support at least one of the -u/--update flags.



            EDIT: the -u/--update flags allow tar to create as well as append to an archive.



            I just noticed that unfortunately, you cannot update compressed archives (tgz, created with the -c flag). However, you can, by all means create a non-compressed archive first and then compress the results.



            Also, it should not confuse you that I'm using flags to tar with a hyphen ('-' character). It accepts both forms. In my example, -uf would be equivalent to uf in yours.



            As for the - option, it is probalby not documented in the man page of tar because it is a very common Unix convention for command line tools that deal with streams as well as named files.
            - us usually a special argument for filters and names the standard input stream as a file.



            EDIT: As Gilles wrote in their very informative answer, which they have however now removed, - is also used to name the standard error stream.
            It depends on which one can be unambiguously assumed. Usually, only one of them makes sense, since the other is specified in some other way.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 6 mins ago

























            answered 48 mins ago









            Larry

            463




            463












            • Good idea, thank you, but unfortunately, looks like Busybox version of tar does not support -u/-update.
              – StoneThrow
              35 mins ago










            • I worked a lot on embedded machines with BusyBox as well. Unfortunately, my only solution was to cross-compile 7Zip for that system.
              – Larry
              28 mins ago










            • -u wouldn't work with a gzipped archive anyway.
              – Gilles
              22 mins ago


















            • Good idea, thank you, but unfortunately, looks like Busybox version of tar does not support -u/-update.
              – StoneThrow
              35 mins ago










            • I worked a lot on embedded machines with BusyBox as well. Unfortunately, my only solution was to cross-compile 7Zip for that system.
              – Larry
              28 mins ago










            • -u wouldn't work with a gzipped archive anyway.
              – Gilles
              22 mins ago
















            Good idea, thank you, but unfortunately, looks like Busybox version of tar does not support -u/-update.
            – StoneThrow
            35 mins ago




            Good idea, thank you, but unfortunately, looks like Busybox version of tar does not support -u/-update.
            – StoneThrow
            35 mins ago












            I worked a lot on embedded machines with BusyBox as well. Unfortunately, my only solution was to cross-compile 7Zip for that system.
            – Larry
            28 mins ago




            I worked a lot on embedded machines with BusyBox as well. Unfortunately, my only solution was to cross-compile 7Zip for that system.
            – Larry
            28 mins ago












            -u wouldn't work with a gzipped archive anyway.
            – Gilles
            22 mins ago




            -u wouldn't work with a gzipped archive anyway.
            – Gilles
            22 mins ago


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f492308%2fportable-way-to-invoke-tar-with-a-list-of-files-from-stdin%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Eastern Orthodox Church

            Zagreb

            Understanding the information contained in the Deep Space Network XML data?