Why is my find not recursive?












53














I am running the following command, but it is not performed recursively:



find . -name *.java


I know there are java files further down in the current directory but it is performing the find on the current directory only. I am using OS X, 10.9.










share|improve this question
























  • @Gilles : This Q&A is much clearer and less localized than the dupe -- if one of them should be closed, it's the other one.
    – goldilocks
    Apr 7 '14 at 1:50
















53














I am running the following command, but it is not performed recursively:



find . -name *.java


I know there are java files further down in the current directory but it is performing the find on the current directory only. I am using OS X, 10.9.










share|improve this question
























  • @Gilles : This Q&A is much clearer and less localized than the dupe -- if one of them should be closed, it's the other one.
    – goldilocks
    Apr 7 '14 at 1:50














53












53








53


10





I am running the following command, but it is not performed recursively:



find . -name *.java


I know there are java files further down in the current directory but it is performing the find on the current directory only. I am using OS X, 10.9.










share|improve this question















I am running the following command, but it is not performed recursively:



find . -name *.java


I know there are java files further down in the current directory but it is performing the find on the current directory only. I am using OS X, 10.9.







shell find wildcards






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 6 '14 at 22:59









Gilles

530k12810621590




530k12810621590










asked Apr 6 '14 at 22:02









user11498user11498

86141124




86141124












  • @Gilles : This Q&A is much clearer and less localized than the dupe -- if one of them should be closed, it's the other one.
    – goldilocks
    Apr 7 '14 at 1:50


















  • @Gilles : This Q&A is much clearer and less localized than the dupe -- if one of them should be closed, it's the other one.
    – goldilocks
    Apr 7 '14 at 1:50
















@Gilles : This Q&A is much clearer and less localized than the dupe -- if one of them should be closed, it's the other one.
– goldilocks
Apr 7 '14 at 1:50




@Gilles : This Q&A is much clearer and less localized than the dupe -- if one of them should be closed, it's the other one.
– goldilocks
Apr 7 '14 at 1:50










3 Answers
3






active

oldest

votes


















77














The problem is, you didn't quote your -name parameter. Do this instead:



find . -name '*.java'


Explanation



Without the quotes, the shell interprets *.java as a glob pattern and expands it to any file names matching the glob before passing it to find. This way, if you had, say, foo.java in the current directory, find's actual command line would be:



find . -name foo.java


which would obviously list the file in the current directory only (unless you happen to have some similarly-named files further down the tree).



Quoting prevents glob expansion and passes the command line to find as-is.



Incidentally, if the glob had failed to match (no *.java files in the current directory), you would get one of two behaviors depending on how your shell is set up to handle globs that don't match (this is governed by the nullglob option in Bash, for example):




  1. If a glob that doesn't match is not expanded by the shell, find will (accidentally, mind you) exhibit correct behavior.

  2. If a glob that doesn't match is expanded into an empty string by the shell, find will complain that it is missing an argument to -name.






share|improve this answer





























    17














    I had a situation similar where I was surrounding the -name value in quotes, but still wasn't getting all of the find hits that I was hoping for. I conjectured that it was because of symlinks and sure enough that was the case. If you want to force find to search through symlinks you can modify the command to the following:



    find -L . -name '*.java'





    share|improve this answer





























      0














      Escape the *



      find . -name *.java





      share|improve this answer





















        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%2f123440%2fwhy-is-my-find-not-recursive%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









        77














        The problem is, you didn't quote your -name parameter. Do this instead:



        find . -name '*.java'


        Explanation



        Without the quotes, the shell interprets *.java as a glob pattern and expands it to any file names matching the glob before passing it to find. This way, if you had, say, foo.java in the current directory, find's actual command line would be:



        find . -name foo.java


        which would obviously list the file in the current directory only (unless you happen to have some similarly-named files further down the tree).



        Quoting prevents glob expansion and passes the command line to find as-is.



        Incidentally, if the glob had failed to match (no *.java files in the current directory), you would get one of two behaviors depending on how your shell is set up to handle globs that don't match (this is governed by the nullglob option in Bash, for example):




        1. If a glob that doesn't match is not expanded by the shell, find will (accidentally, mind you) exhibit correct behavior.

        2. If a glob that doesn't match is expanded into an empty string by the shell, find will complain that it is missing an argument to -name.






        share|improve this answer


























          77














          The problem is, you didn't quote your -name parameter. Do this instead:



          find . -name '*.java'


          Explanation



          Without the quotes, the shell interprets *.java as a glob pattern and expands it to any file names matching the glob before passing it to find. This way, if you had, say, foo.java in the current directory, find's actual command line would be:



          find . -name foo.java


          which would obviously list the file in the current directory only (unless you happen to have some similarly-named files further down the tree).



          Quoting prevents glob expansion and passes the command line to find as-is.



          Incidentally, if the glob had failed to match (no *.java files in the current directory), you would get one of two behaviors depending on how your shell is set up to handle globs that don't match (this is governed by the nullglob option in Bash, for example):




          1. If a glob that doesn't match is not expanded by the shell, find will (accidentally, mind you) exhibit correct behavior.

          2. If a glob that doesn't match is expanded into an empty string by the shell, find will complain that it is missing an argument to -name.






          share|improve this answer
























            77












            77








            77






            The problem is, you didn't quote your -name parameter. Do this instead:



            find . -name '*.java'


            Explanation



            Without the quotes, the shell interprets *.java as a glob pattern and expands it to any file names matching the glob before passing it to find. This way, if you had, say, foo.java in the current directory, find's actual command line would be:



            find . -name foo.java


            which would obviously list the file in the current directory only (unless you happen to have some similarly-named files further down the tree).



            Quoting prevents glob expansion and passes the command line to find as-is.



            Incidentally, if the glob had failed to match (no *.java files in the current directory), you would get one of two behaviors depending on how your shell is set up to handle globs that don't match (this is governed by the nullglob option in Bash, for example):




            1. If a glob that doesn't match is not expanded by the shell, find will (accidentally, mind you) exhibit correct behavior.

            2. If a glob that doesn't match is expanded into an empty string by the shell, find will complain that it is missing an argument to -name.






            share|improve this answer












            The problem is, you didn't quote your -name parameter. Do this instead:



            find . -name '*.java'


            Explanation



            Without the quotes, the shell interprets *.java as a glob pattern and expands it to any file names matching the glob before passing it to find. This way, if you had, say, foo.java in the current directory, find's actual command line would be:



            find . -name foo.java


            which would obviously list the file in the current directory only (unless you happen to have some similarly-named files further down the tree).



            Quoting prevents glob expansion and passes the command line to find as-is.



            Incidentally, if the glob had failed to match (no *.java files in the current directory), you would get one of two behaviors depending on how your shell is set up to handle globs that don't match (this is governed by the nullglob option in Bash, for example):




            1. If a glob that doesn't match is not expanded by the shell, find will (accidentally, mind you) exhibit correct behavior.

            2. If a glob that doesn't match is expanded into an empty string by the shell, find will complain that it is missing an argument to -name.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Apr 6 '14 at 22:04









            Joseph R.Joseph R.

            28.1k374114




            28.1k374114

























                17














                I had a situation similar where I was surrounding the -name value in quotes, but still wasn't getting all of the find hits that I was hoping for. I conjectured that it was because of symlinks and sure enough that was the case. If you want to force find to search through symlinks you can modify the command to the following:



                find -L . -name '*.java'





                share|improve this answer


























                  17














                  I had a situation similar where I was surrounding the -name value in quotes, but still wasn't getting all of the find hits that I was hoping for. I conjectured that it was because of symlinks and sure enough that was the case. If you want to force find to search through symlinks you can modify the command to the following:



                  find -L . -name '*.java'





                  share|improve this answer
























                    17












                    17








                    17






                    I had a situation similar where I was surrounding the -name value in quotes, but still wasn't getting all of the find hits that I was hoping for. I conjectured that it was because of symlinks and sure enough that was the case. If you want to force find to search through symlinks you can modify the command to the following:



                    find -L . -name '*.java'





                    share|improve this answer












                    I had a situation similar where I was surrounding the -name value in quotes, but still wasn't getting all of the find hits that I was hoping for. I conjectured that it was because of symlinks and sure enough that was the case. If you want to force find to search through symlinks you can modify the command to the following:



                    find -L . -name '*.java'






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Aug 5 '15 at 22:32









                    gaoagonggaoagong

                    27123




                    27123























                        0














                        Escape the *



                        find . -name *.java





                        share|improve this answer


























                          0














                          Escape the *



                          find . -name *.java





                          share|improve this answer
























                            0












                            0








                            0






                            Escape the *



                            find . -name *.java





                            share|improve this answer












                            Escape the *



                            find . -name *.java






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Dec 31 '18 at 14:39









                            Stuart CardallStuart Cardall

                            831610




                            831610






























                                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.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f123440%2fwhy-is-my-find-not-recursive%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

                                Morgemoulin

                                Scott Moir

                                Souastre