List files recursively on OSX?

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











up vote
1
down vote

favorite












I want to find all PDF files in a directory and its subdirectories, on OSX.



I know there are some PDFs in subdirectories, because e.g. this produces lots of results:



ls myfolder/pdfs/*.pdf


All my Googling suggests I want ls -R, but this produces no results:



ls -R *.pdf


What am I doing wrong?



I can find some results this way:



ls -R | grep pdf


But I can't see this full paths to the files, which isn't very helpful.







share|improve this question




















  • You want to use find rather.
    – Ralph Rönnquist
    Mar 24 at 11:31














up vote
1
down vote

favorite












I want to find all PDF files in a directory and its subdirectories, on OSX.



I know there are some PDFs in subdirectories, because e.g. this produces lots of results:



ls myfolder/pdfs/*.pdf


All my Googling suggests I want ls -R, but this produces no results:



ls -R *.pdf


What am I doing wrong?



I can find some results this way:



ls -R | grep pdf


But I can't see this full paths to the files, which isn't very helpful.







share|improve this question




















  • You want to use find rather.
    – Ralph Rönnquist
    Mar 24 at 11:31












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I want to find all PDF files in a directory and its subdirectories, on OSX.



I know there are some PDFs in subdirectories, because e.g. this produces lots of results:



ls myfolder/pdfs/*.pdf


All my Googling suggests I want ls -R, but this produces no results:



ls -R *.pdf


What am I doing wrong?



I can find some results this way:



ls -R | grep pdf


But I can't see this full paths to the files, which isn't very helpful.







share|improve this question












I want to find all PDF files in a directory and its subdirectories, on OSX.



I know there are some PDFs in subdirectories, because e.g. this produces lots of results:



ls myfolder/pdfs/*.pdf


All my Googling suggests I want ls -R, but this produces no results:



ls -R *.pdf


What am I doing wrong?



I can find some results this way:



ls -R | grep pdf


But I can't see this full paths to the files, which isn't very helpful.









share|improve this question











share|improve this question




share|improve this question










asked Mar 24 at 11:29









Richard

623189




623189











  • You want to use find rather.
    – Ralph Rönnquist
    Mar 24 at 11:31
















  • You want to use find rather.
    – Ralph Rönnquist
    Mar 24 at 11:31















You want to use find rather.
– Ralph Rönnquist
Mar 24 at 11:31




You want to use find rather.
– Ralph Rönnquist
Mar 24 at 11:31










3 Answers
3






active

oldest

votes

















up vote
0
down vote



accepted










ls -R *.pdf would invoke ls recursively on anything matching *.pdf (if there's nothing matching *.pdf in the current directory, you'll get no result, and if there is, it will only recurse into it if it's a directory). ls -R | grep pdf would show you everything in the ls -R result that matches the regular expression pdf, which is not what you want.



This is what you need:



find myfolder -type f -name '*.pdf'


This will give you the pathnames of all regular files (-type f) in or below the myfolder directory whose filenames matches the pattern *.pdf. The pattern needs to be quoted to protect it from the shell.






share|improve this answer



























    up vote
    2
    down vote













    On the native bash shell you have on macOS Terminal, enable an extended glob option globstar to enable recursive glob match on nested sub-directories.



    shopt -s globstar nullglob
    ls **/*.pdf


    The nullglob prevents filename patterns which match no files to expand to a null string, rather than themselves. With globstar, the pattern ** used in a filename expansion context will match all files and zero or more directories and sub-directories.



    To be a bit safe by avoiding setting the shell options on the current shell, you can set it in sub-shell instead



    ( shopt -s globstar nullglob; ls **/*.pdf )





    share|improve this answer





























      up vote
      0
      down vote













      try



      find . -name *.pdf -print


      this should list pdf like



      myfolder/foo/doc1.pdf
      myfolder/bar/foo/doc2.pdf


      note that * in *.pdf must be escaped if there is a pdf in starting directory.






      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',
        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%2f433248%2flist-files-recursively-on-osx%23new-answer', 'question_page');

        );

        Post as a guest






























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        0
        down vote



        accepted










        ls -R *.pdf would invoke ls recursively on anything matching *.pdf (if there's nothing matching *.pdf in the current directory, you'll get no result, and if there is, it will only recurse into it if it's a directory). ls -R | grep pdf would show you everything in the ls -R result that matches the regular expression pdf, which is not what you want.



        This is what you need:



        find myfolder -type f -name '*.pdf'


        This will give you the pathnames of all regular files (-type f) in or below the myfolder directory whose filenames matches the pattern *.pdf. The pattern needs to be quoted to protect it from the shell.






        share|improve this answer
























          up vote
          0
          down vote



          accepted










          ls -R *.pdf would invoke ls recursively on anything matching *.pdf (if there's nothing matching *.pdf in the current directory, you'll get no result, and if there is, it will only recurse into it if it's a directory). ls -R | grep pdf would show you everything in the ls -R result that matches the regular expression pdf, which is not what you want.



          This is what you need:



          find myfolder -type f -name '*.pdf'


          This will give you the pathnames of all regular files (-type f) in or below the myfolder directory whose filenames matches the pattern *.pdf. The pattern needs to be quoted to protect it from the shell.






          share|improve this answer






















            up vote
            0
            down vote



            accepted







            up vote
            0
            down vote



            accepted






            ls -R *.pdf would invoke ls recursively on anything matching *.pdf (if there's nothing matching *.pdf in the current directory, you'll get no result, and if there is, it will only recurse into it if it's a directory). ls -R | grep pdf would show you everything in the ls -R result that matches the regular expression pdf, which is not what you want.



            This is what you need:



            find myfolder -type f -name '*.pdf'


            This will give you the pathnames of all regular files (-type f) in or below the myfolder directory whose filenames matches the pattern *.pdf. The pattern needs to be quoted to protect it from the shell.






            share|improve this answer












            ls -R *.pdf would invoke ls recursively on anything matching *.pdf (if there's nothing matching *.pdf in the current directory, you'll get no result, and if there is, it will only recurse into it if it's a directory). ls -R | grep pdf would show you everything in the ls -R result that matches the regular expression pdf, which is not what you want.



            This is what you need:



            find myfolder -type f -name '*.pdf'


            This will give you the pathnames of all regular files (-type f) in or below the myfolder directory whose filenames matches the pattern *.pdf. The pattern needs to be quoted to protect it from the shell.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 24 at 11:34









            Kusalananda

            102k13201317




            102k13201317






















                up vote
                2
                down vote













                On the native bash shell you have on macOS Terminal, enable an extended glob option globstar to enable recursive glob match on nested sub-directories.



                shopt -s globstar nullglob
                ls **/*.pdf


                The nullglob prevents filename patterns which match no files to expand to a null string, rather than themselves. With globstar, the pattern ** used in a filename expansion context will match all files and zero or more directories and sub-directories.



                To be a bit safe by avoiding setting the shell options on the current shell, you can set it in sub-shell instead



                ( shopt -s globstar nullglob; ls **/*.pdf )





                share|improve this answer


























                  up vote
                  2
                  down vote













                  On the native bash shell you have on macOS Terminal, enable an extended glob option globstar to enable recursive glob match on nested sub-directories.



                  shopt -s globstar nullglob
                  ls **/*.pdf


                  The nullglob prevents filename patterns which match no files to expand to a null string, rather than themselves. With globstar, the pattern ** used in a filename expansion context will match all files and zero or more directories and sub-directories.



                  To be a bit safe by avoiding setting the shell options on the current shell, you can set it in sub-shell instead



                  ( shopt -s globstar nullglob; ls **/*.pdf )





                  share|improve this answer
























                    up vote
                    2
                    down vote










                    up vote
                    2
                    down vote









                    On the native bash shell you have on macOS Terminal, enable an extended glob option globstar to enable recursive glob match on nested sub-directories.



                    shopt -s globstar nullglob
                    ls **/*.pdf


                    The nullglob prevents filename patterns which match no files to expand to a null string, rather than themselves. With globstar, the pattern ** used in a filename expansion context will match all files and zero or more directories and sub-directories.



                    To be a bit safe by avoiding setting the shell options on the current shell, you can set it in sub-shell instead



                    ( shopt -s globstar nullglob; ls **/*.pdf )





                    share|improve this answer














                    On the native bash shell you have on macOS Terminal, enable an extended glob option globstar to enable recursive glob match on nested sub-directories.



                    shopt -s globstar nullglob
                    ls **/*.pdf


                    The nullglob prevents filename patterns which match no files to expand to a null string, rather than themselves. With globstar, the pattern ** used in a filename expansion context will match all files and zero or more directories and sub-directories.



                    To be a bit safe by avoiding setting the shell options on the current shell, you can set it in sub-shell instead



                    ( shopt -s globstar nullglob; ls **/*.pdf )






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Mar 24 at 16:50

























                    answered Mar 24 at 11:42









                    Inian

                    2,855722




                    2,855722




















                        up vote
                        0
                        down vote













                        try



                        find . -name *.pdf -print


                        this should list pdf like



                        myfolder/foo/doc1.pdf
                        myfolder/bar/foo/doc2.pdf


                        note that * in *.pdf must be escaped if there is a pdf in starting directory.






                        share|improve this answer
























                          up vote
                          0
                          down vote













                          try



                          find . -name *.pdf -print


                          this should list pdf like



                          myfolder/foo/doc1.pdf
                          myfolder/bar/foo/doc2.pdf


                          note that * in *.pdf must be escaped if there is a pdf in starting directory.






                          share|improve this answer






















                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            try



                            find . -name *.pdf -print


                            this should list pdf like



                            myfolder/foo/doc1.pdf
                            myfolder/bar/foo/doc2.pdf


                            note that * in *.pdf must be escaped if there is a pdf in starting directory.






                            share|improve this answer












                            try



                            find . -name *.pdf -print


                            this should list pdf like



                            myfolder/foo/doc1.pdf
                            myfolder/bar/foo/doc2.pdf


                            note that * in *.pdf must be escaped if there is a pdf in starting directory.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Mar 24 at 11:33









                            Archemar

                            18.9k93366




                            18.9k93366






















                                 

                                draft saved


                                draft discarded


























                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f433248%2flist-files-recursively-on-osx%23new-answer', 'question_page');

                                );

                                Post as a guest













































































                                Popular posts from this blog

                                How to check contact read email or not when send email to Individual?

                                Bahrain

                                Postfix configuration issue with fips on centos 7; mailgun relay