search through all *.py files [duplicate]

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












1















This question already has an answer here:



  • How to list .txt files with specific content?

    4 answers



I am using Mac OS terminal (similar to Linux) and trying to find best way to search inside all files on a computer that has extension *.py



What is the best way to achieve this?



I wanted to put 1 keyword for search and quickly show the whole path of these python files are that contain requested keyword in them..










share|improve this question















marked as duplicate by Mikel, muru, Jeff Schaller, schily, RalfFriedl Dec 11 at 18:23


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















    1















    This question already has an answer here:



    • How to list .txt files with specific content?

      4 answers



    I am using Mac OS terminal (similar to Linux) and trying to find best way to search inside all files on a computer that has extension *.py



    What is the best way to achieve this?



    I wanted to put 1 keyword for search and quickly show the whole path of these python files are that contain requested keyword in them..










    share|improve this question















    marked as duplicate by Mikel, muru, Jeff Schaller, schily, RalfFriedl Dec 11 at 18:23


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

















      1












      1








      1








      This question already has an answer here:



      • How to list .txt files with specific content?

        4 answers



      I am using Mac OS terminal (similar to Linux) and trying to find best way to search inside all files on a computer that has extension *.py



      What is the best way to achieve this?



      I wanted to put 1 keyword for search and quickly show the whole path of these python files are that contain requested keyword in them..










      share|improve this question
















      This question already has an answer here:



      • How to list .txt files with specific content?

        4 answers



      I am using Mac OS terminal (similar to Linux) and trying to find best way to search inside all files on a computer that has extension *.py



      What is the best way to achieve this?



      I wanted to put 1 keyword for search and quickly show the whole path of these python files are that contain requested keyword in them..





      This question already has an answer here:



      • How to list .txt files with specific content?

        4 answers







      command-line grep find osx python






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 11 at 18:36









      Rui F Ribeiro

      38.8k1479128




      38.8k1479128










      asked Dec 11 at 15:28









      Joe

      1062




      1062




      marked as duplicate by Mikel, muru, Jeff Schaller, schily, RalfFriedl Dec 11 at 18:23


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by Mikel, muru, Jeff Schaller, schily, RalfFriedl Dec 11 at 18:23


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






















          2 Answers
          2






          active

          oldest

          votes


















          3














          Try this,



          find / -name '*.py' -exec grep -l "keyword" ;


          Explanation:




          • find / -name '*.py': Find files below / with py extension.


          • -exec grep -l keyword ; Within the files found, grep for keyword and output the filename instead of the match -l.


          I'm not familiar with Mac OS, but if you have globstar option in your shell, you can use the following:



          shopt -s globstar
          grep -l keyword /**/*.py





          share|improve this answer






















          • I think mac has bash shell (same as Gnu/Linux), but by default not all gnu tools (some are bsd). Your find finds files ending .py (there is no such thing as file-name-extensions, on Unix).
            – ctrl-alt-delor
            Dec 11 at 15:54


















          0














          To look for the string needle in a bunch of Python files in a haystack directory:



          $ grep -l 'needle' haystack/*.py


          To descend into a directory tree, you could either use grep -R or switch to iterating via find as in the answer from RoVo.






          share|improve this answer



























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3














            Try this,



            find / -name '*.py' -exec grep -l "keyword" ;


            Explanation:




            • find / -name '*.py': Find files below / with py extension.


            • -exec grep -l keyword ; Within the files found, grep for keyword and output the filename instead of the match -l.


            I'm not familiar with Mac OS, but if you have globstar option in your shell, you can use the following:



            shopt -s globstar
            grep -l keyword /**/*.py





            share|improve this answer






















            • I think mac has bash shell (same as Gnu/Linux), but by default not all gnu tools (some are bsd). Your find finds files ending .py (there is no such thing as file-name-extensions, on Unix).
              – ctrl-alt-delor
              Dec 11 at 15:54















            3














            Try this,



            find / -name '*.py' -exec grep -l "keyword" ;


            Explanation:




            • find / -name '*.py': Find files below / with py extension.


            • -exec grep -l keyword ; Within the files found, grep for keyword and output the filename instead of the match -l.


            I'm not familiar with Mac OS, but if you have globstar option in your shell, you can use the following:



            shopt -s globstar
            grep -l keyword /**/*.py





            share|improve this answer






















            • I think mac has bash shell (same as Gnu/Linux), but by default not all gnu tools (some are bsd). Your find finds files ending .py (there is no such thing as file-name-extensions, on Unix).
              – ctrl-alt-delor
              Dec 11 at 15:54













            3












            3








            3






            Try this,



            find / -name '*.py' -exec grep -l "keyword" ;


            Explanation:




            • find / -name '*.py': Find files below / with py extension.


            • -exec grep -l keyword ; Within the files found, grep for keyword and output the filename instead of the match -l.


            I'm not familiar with Mac OS, but if you have globstar option in your shell, you can use the following:



            shopt -s globstar
            grep -l keyword /**/*.py





            share|improve this answer














            Try this,



            find / -name '*.py' -exec grep -l "keyword" ;


            Explanation:




            • find / -name '*.py': Find files below / with py extension.


            • -exec grep -l keyword ; Within the files found, grep for keyword and output the filename instead of the match -l.


            I'm not familiar with Mac OS, but if you have globstar option in your shell, you can use the following:



            shopt -s globstar
            grep -l keyword /**/*.py






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Dec 11 at 15:37

























            answered Dec 11 at 15:32









            RoVo

            2,558215




            2,558215











            • I think mac has bash shell (same as Gnu/Linux), but by default not all gnu tools (some are bsd). Your find finds files ending .py (there is no such thing as file-name-extensions, on Unix).
              – ctrl-alt-delor
              Dec 11 at 15:54
















            • I think mac has bash shell (same as Gnu/Linux), but by default not all gnu tools (some are bsd). Your find finds files ending .py (there is no such thing as file-name-extensions, on Unix).
              – ctrl-alt-delor
              Dec 11 at 15:54















            I think mac has bash shell (same as Gnu/Linux), but by default not all gnu tools (some are bsd). Your find finds files ending .py (there is no such thing as file-name-extensions, on Unix).
            – ctrl-alt-delor
            Dec 11 at 15:54




            I think mac has bash shell (same as Gnu/Linux), but by default not all gnu tools (some are bsd). Your find finds files ending .py (there is no such thing as file-name-extensions, on Unix).
            – ctrl-alt-delor
            Dec 11 at 15:54













            0














            To look for the string needle in a bunch of Python files in a haystack directory:



            $ grep -l 'needle' haystack/*.py


            To descend into a directory tree, you could either use grep -R or switch to iterating via find as in the answer from RoVo.






            share|improve this answer

























              0














              To look for the string needle in a bunch of Python files in a haystack directory:



              $ grep -l 'needle' haystack/*.py


              To descend into a directory tree, you could either use grep -R or switch to iterating via find as in the answer from RoVo.






              share|improve this answer























                0












                0








                0






                To look for the string needle in a bunch of Python files in a haystack directory:



                $ grep -l 'needle' haystack/*.py


                To descend into a directory tree, you could either use grep -R or switch to iterating via find as in the answer from RoVo.






                share|improve this answer












                To look for the string needle in a bunch of Python files in a haystack directory:



                $ grep -l 'needle' haystack/*.py


                To descend into a directory tree, you could either use grep -R or switch to iterating via find as in the answer from RoVo.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 11 at 15:36









                DopeGhoti

                43.1k55382




                43.1k55382












                    Popular posts from this blog

                    Peggy Mitchell

                    Palaiologos

                    The Forum (Inglewood, California)