Find an archive and extract it in the directory where it is located











up vote
0
down vote

favorite












I want to find a tar file which is presented in any directory and un-archive it in a one line command. I am able to find it separately from home directory. but only can extract it from directory where it is located. How can I do both in a single line using pipe?



find -name any.tar ; tar xf any.tar I tried with this.. I can able to find this any.tar file from any directory separately. And tar xf is also extracting the file sparately but only in the dir where any.tar is located. I want run both command in a single line which can find the any.tar and extract it when the command is compiled from home directory.



I am entirely new to Unix please help me out.Thank you.










share|improve this question
























  • Show us what you can do. If you show that you made an effort you will get more help. Also it may help us to see what you are trying to do, and prevent down votes.
    – ctrl-alt-delor
    Sep 6 '14 at 22:08










  • Fix the question, instead of adding comments to explain itp
    – ctrl-alt-delor
    Sep 7 '14 at 9:02















up vote
0
down vote

favorite












I want to find a tar file which is presented in any directory and un-archive it in a one line command. I am able to find it separately from home directory. but only can extract it from directory where it is located. How can I do both in a single line using pipe?



find -name any.tar ; tar xf any.tar I tried with this.. I can able to find this any.tar file from any directory separately. And tar xf is also extracting the file sparately but only in the dir where any.tar is located. I want run both command in a single line which can find the any.tar and extract it when the command is compiled from home directory.



I am entirely new to Unix please help me out.Thank you.










share|improve this question
























  • Show us what you can do. If you show that you made an effort you will get more help. Also it may help us to see what you are trying to do, and prevent down votes.
    – ctrl-alt-delor
    Sep 6 '14 at 22:08










  • Fix the question, instead of adding comments to explain itp
    – ctrl-alt-delor
    Sep 7 '14 at 9:02













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I want to find a tar file which is presented in any directory and un-archive it in a one line command. I am able to find it separately from home directory. but only can extract it from directory where it is located. How can I do both in a single line using pipe?



find -name any.tar ; tar xf any.tar I tried with this.. I can able to find this any.tar file from any directory separately. And tar xf is also extracting the file sparately but only in the dir where any.tar is located. I want run both command in a single line which can find the any.tar and extract it when the command is compiled from home directory.



I am entirely new to Unix please help me out.Thank you.










share|improve this question















I want to find a tar file which is presented in any directory and un-archive it in a one line command. I am able to find it separately from home directory. but only can extract it from directory where it is located. How can I do both in a single line using pipe?



find -name any.tar ; tar xf any.tar I tried with this.. I can able to find this any.tar file from any directory separately. And tar xf is also extracting the file sparately but only in the dir where any.tar is located. I want run both command in a single line which can find the any.tar and extract it when the command is compiled from home directory.



I am entirely new to Unix please help me out.Thank you.







shell find tar






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 7 '14 at 9:09









ctrl-alt-delor

10.4k41955




10.4k41955










asked Sep 6 '14 at 17:40









CSE

11




11












  • Show us what you can do. If you show that you made an effort you will get more help. Also it may help us to see what you are trying to do, and prevent down votes.
    – ctrl-alt-delor
    Sep 6 '14 at 22:08










  • Fix the question, instead of adding comments to explain itp
    – ctrl-alt-delor
    Sep 7 '14 at 9:02


















  • Show us what you can do. If you show that you made an effort you will get more help. Also it may help us to see what you are trying to do, and prevent down votes.
    – ctrl-alt-delor
    Sep 6 '14 at 22:08










  • Fix the question, instead of adding comments to explain itp
    – ctrl-alt-delor
    Sep 7 '14 at 9:02
















Show us what you can do. If you show that you made an effort you will get more help. Also it may help us to see what you are trying to do, and prevent down votes.
– ctrl-alt-delor
Sep 6 '14 at 22:08




Show us what you can do. If you show that you made an effort you will get more help. Also it may help us to see what you are trying to do, and prevent down votes.
– ctrl-alt-delor
Sep 6 '14 at 22:08












Fix the question, instead of adding comments to explain itp
– ctrl-alt-delor
Sep 7 '14 at 9:02




Fix the question, instead of adding comments to explain itp
– ctrl-alt-delor
Sep 7 '14 at 9:02










3 Answers
3






active

oldest

votes

















up vote
2
down vote













This might help



find ./ -name '*.tar' -exec sh -c 'dir=$(dirname "$0"); tar -xvf "${0}" -C "${dir}"; done' {} ;


From man page of tar



-C, --directory DIR
change to directory DIR





share|improve this answer






























    up vote
    0
    down vote













    First is find:



    To find all tar files in a directory you will need find $directory -iname "*.tar" Note: -iname is a gnu extension, so if you are not using gnu you will have to do -name *.tar -o -name *.TAR this is almost equivalent.



    Now to add your working tar command:



    find $directory -iname "*.tar" -print0 | xargs -0 --max-args=1 tar xf



    This will extract all the tar files into the current working directory.






    share|improve this answer




























      up vote
      0
      down vote













      I found this page searching for the same question, the suggestion didn't directly work for me, but tweaking it a little bit worked for my use case:



      find . -name "*.tar" -exec sh -c 'tar xvf {} -C $(dirname {})' ;





      share|improve this answer








      New contributor




      Tom is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.


















        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: 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%2f154110%2ffind-an-archive-and-extract-it-in-the-directory-where-it-is-located%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








        up vote
        2
        down vote













        This might help



        find ./ -name '*.tar' -exec sh -c 'dir=$(dirname "$0"); tar -xvf "${0}" -C "${dir}"; done' {} ;


        From man page of tar



        -C, --directory DIR
        change to directory DIR





        share|improve this answer



























          up vote
          2
          down vote













          This might help



          find ./ -name '*.tar' -exec sh -c 'dir=$(dirname "$0"); tar -xvf "${0}" -C "${dir}"; done' {} ;


          From man page of tar



          -C, --directory DIR
          change to directory DIR





          share|improve this answer

























            up vote
            2
            down vote










            up vote
            2
            down vote









            This might help



            find ./ -name '*.tar' -exec sh -c 'dir=$(dirname "$0"); tar -xvf "${0}" -C "${dir}"; done' {} ;


            From man page of tar



            -C, --directory DIR
            change to directory DIR





            share|improve this answer














            This might help



            find ./ -name '*.tar' -exec sh -c 'dir=$(dirname "$0"); tar -xvf "${0}" -C "${dir}"; done' {} ;


            From man page of tar



            -C, --directory DIR
            change to directory DIR






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Sep 7 '14 at 10:14

























            answered Sep 6 '14 at 19:02









            g4ur4v

            68451830




            68451830
























                up vote
                0
                down vote













                First is find:



                To find all tar files in a directory you will need find $directory -iname "*.tar" Note: -iname is a gnu extension, so if you are not using gnu you will have to do -name *.tar -o -name *.TAR this is almost equivalent.



                Now to add your working tar command:



                find $directory -iname "*.tar" -print0 | xargs -0 --max-args=1 tar xf



                This will extract all the tar files into the current working directory.






                share|improve this answer

























                  up vote
                  0
                  down vote













                  First is find:



                  To find all tar files in a directory you will need find $directory -iname "*.tar" Note: -iname is a gnu extension, so if you are not using gnu you will have to do -name *.tar -o -name *.TAR this is almost equivalent.



                  Now to add your working tar command:



                  find $directory -iname "*.tar" -print0 | xargs -0 --max-args=1 tar xf



                  This will extract all the tar files into the current working directory.






                  share|improve this answer























                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    First is find:



                    To find all tar files in a directory you will need find $directory -iname "*.tar" Note: -iname is a gnu extension, so if you are not using gnu you will have to do -name *.tar -o -name *.TAR this is almost equivalent.



                    Now to add your working tar command:



                    find $directory -iname "*.tar" -print0 | xargs -0 --max-args=1 tar xf



                    This will extract all the tar files into the current working directory.






                    share|improve this answer












                    First is find:



                    To find all tar files in a directory you will need find $directory -iname "*.tar" Note: -iname is a gnu extension, so if you are not using gnu you will have to do -name *.tar -o -name *.TAR this is almost equivalent.



                    Now to add your working tar command:



                    find $directory -iname "*.tar" -print0 | xargs -0 --max-args=1 tar xf



                    This will extract all the tar files into the current working directory.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Sep 7 '14 at 9:26









                    ctrl-alt-delor

                    10.4k41955




                    10.4k41955






















                        up vote
                        0
                        down vote













                        I found this page searching for the same question, the suggestion didn't directly work for me, but tweaking it a little bit worked for my use case:



                        find . -name "*.tar" -exec sh -c 'tar xvf {} -C $(dirname {})' ;





                        share|improve this answer








                        New contributor




                        Tom is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.






















                          up vote
                          0
                          down vote













                          I found this page searching for the same question, the suggestion didn't directly work for me, but tweaking it a little bit worked for my use case:



                          find . -name "*.tar" -exec sh -c 'tar xvf {} -C $(dirname {})' ;





                          share|improve this answer








                          New contributor




                          Tom is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.




















                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            I found this page searching for the same question, the suggestion didn't directly work for me, but tweaking it a little bit worked for my use case:



                            find . -name "*.tar" -exec sh -c 'tar xvf {} -C $(dirname {})' ;





                            share|improve this answer








                            New contributor




                            Tom is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.









                            I found this page searching for the same question, the suggestion didn't directly work for me, but tweaking it a little bit worked for my use case:



                            find . -name "*.tar" -exec sh -c 'tar xvf {} -C $(dirname {})' ;






                            share|improve this answer








                            New contributor




                            Tom is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.









                            share|improve this answer



                            share|improve this answer






                            New contributor




                            Tom is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.









                            answered 2 days ago









                            Tom

                            1




                            1




                            New contributor




                            Tom is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.





                            New contributor





                            Tom is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.






                            Tom is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.






























                                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%2f154110%2ffind-an-archive-and-extract-it-in-the-directory-where-it-is-located%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

                                Entries order in /etc/network/interfaces

                                新発田市

                                Grub takes very long (several minutes) to open Menu (in Multi-Boot-System)