Linux/Mac Terminal Tutorial: The Grep Command - Search Files and Directories for Patterns of Text

Поделиться
HTML-код
  • Опубликовано: 6 мар 2018
  • In this Linux/Mac terminal tutorial, we will be learning how to use the grep command. The grep command allows us to search files and directories for patterns of text. You can also pipe the output of one command into grep to get certain matches. It's extremely useful once you learn the ins and outs. Let's get started...
    The code from this video can be found at:
    github.com/CoreyMSchafer/code...
    Regular Expressions Tutorial: • Regular Expressions (R...
    Regular Expressions Tutorial (Python): • Python Tutorial: re Mo...
    ✅ Support My Channel Through Patreon:
    / coreyms
    ✅ Become a Channel Member:
    / @coreyms
    ✅ One-Time Contribution Through PayPal:
    goo.gl/649HFY
    ✅ Cryptocurrency Donations:
    Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
    Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33
    Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot
    ✅ Corey's Public Amazon Wishlist
    a.co/inIyro1
    ✅ Equipment I Use and Books I Recommend:
    www.amazon.com/shop/coreyschafer
    ▶️ You Can Find Me On:
    My Website - coreyms.com/
    My Second Channel - / coreymschafer
    Facebook - / coreymschafer
    Twitter - / coreymschafer
    Instagram - / coreymschafer
    #Linux #Mac

Комментарии • 239

  • @latlov
    @latlov 3 года назад +110

    6:35 $ grep -win -C 2 "find this string" ./*
    8:05 $ grep -winr "Find that string even in subdirs" ./*
    9:35 $ grep -wirl "List those files that contain this string in current directory dot" .
    10:20 $ grep -wirc "List those files that contain this string and number of occurrences in current directory dot" .
    11:10 $ history | grep "search for git commits in history"
    12:00 $ history | grep "search for git commits" | grep "now narrow down to some string"
    15:40 only for mac: $ brew install grep --with-default-names #to allow regular expressions based on perl, as shown in 17:56.
    19:13 Homework!

  • @whenthethebeansstrikeback6728
    @whenthethebeansstrikeback6728 4 года назад +267

    I like that this guy just gets straight to the point and wastes no time. I like this man already!

    • @kendall.jenner
      @kendall.jenner 4 года назад +2

      Same! Love the no bs

    • @richardgray8593
      @richardgray8593 3 года назад +2

      I'd like it even better if he would take just a sec to give a shout-out to the Greatest President That Ever Was or Ever Will Be, Donald J. Trump.

    • @caitlingibbons2246
      @caitlingibbons2246 3 года назад

      @@richardgray8593 LOL! Don the Con is a sociopathic narcissist. He is, and will always be, the worst "president" to ever trespass in The White House. Good riddance to this parasite.

    • @richardgray8593
      @richardgray8593 3 года назад

      @@caitlingibbons2246 You are pathetically stupid to post something like this. Every day, Joe and the Ho are showing us what a great president Trump truly was.

  • @Spladoinkal
    @Spladoinkal Месяц назад +2

    Wow your tutorial made grep SO much simpler. Thanks!

  • @CrushOfSiel
    @CrushOfSiel 4 года назад +5

    So glad I looked at this tutorial. I've known how to kind of use grep for a while. Some of these options are going to be super helpful to me in the near future. I should have looked in the man pages a long time ago!

  • @msurajnair7149
    @msurajnair7149 3 года назад +1

    There are very few tutorial which gets straight to the point, this is one of them. Really enjoyed learning, Extremely instructive.
    Thank you.

  • @uuzumakifox9
    @uuzumakifox9 3 года назад +2

    I just ended up watching your Python OOP series. and i randomly looked for some Linux tutorials, and i was SOOO happy to see your name!

  • @ahmedmahdy6036
    @ahmedmahdy6036 6 лет назад +48

    awesome ...I really like your style in explanation Corey which i feel like i'm enjoying while watching your tutorials :)

  • @kenthn5396
    @kenthn5396 4 года назад +3

    I like how this was explained. Straight to the point and simple, very easy to understand.

  • @JordanCrawfordSF
    @JordanCrawfordSF 5 лет назад +3

    Brilliant.
    Thank you for taking the time to help me understand grep, I really appreciate your thoughtfulness Corey.

  • @mathewkargarzadeh3158
    @mathewkargarzadeh3158 6 лет назад +4

    outstanding !!!. Dear Corey, appreciate for your time posting your tutorials. I am enjoying teaching style. Thanks again!!

  • @VishKnew
    @VishKnew 3 года назад +2

    Mann....You are a legend...Only few people are out there like you..You really are a gemstone. Thank you soo much for this awesome tutorial brother ❤️ No wasting time, straight to the point. God bless you.
    Love from Kerala ❤️

  • @j0hn4th4nd03
    @j0hn4th4nd03 5 лет назад +3

    Clearest most concise tutorial I have found! Thank you!

  • @younesmdarhrialaoui643
    @younesmdarhrialaoui643 Год назад +1

    Excellent. Straight to the point. Concise and precise. Love it 🤩

  • @apolodu7852
    @apolodu7852 2 года назад +1

    You've made learning these commands so easy, great job and thank you!

  • @mickaelriga8169
    @mickaelriga8169 4 года назад +2

    Great video ! Great explanation. I like that it goes beyond the basic use. Thank you for sharing.

  • @evrensen1520
    @evrensen1520 4 года назад +1

    I love your tutorials. Really enjoyable. Thanks a bunch.

  • @kevinduigou3212
    @kevinduigou3212 6 лет назад +3

    Simple and clear. Thank you!

  • @khuenlau4602
    @khuenlau4602 4 года назад

    Thanks for creating this video, have been searching on how bash commands filter text files, can't find anything helpful, glad I searched it on RUclips.

  • @praisehymnproject319
    @praisehymnproject319 4 года назад +1

    Such a useful and straight forward video! Awesome!

  • @vathsama
    @vathsama 5 лет назад +1

    excellent video, a good start for grep...much appreciated

  • @Hamzaelbouti
    @Hamzaelbouti 6 лет назад +5

    YOU ARE AMAZING ...... DO NOT EVER STOP

  • @kalef1234
    @kalef1234 5 лет назад +3

    finally a nicely done video on this! Thanks

  • @nicholasbarning8250
    @nicholasbarning8250 5 лет назад +1

    awesome video and easy to understand! THANK YOU!

  • @katexie1069
    @katexie1069 2 года назад

    Thank you!! This tutorial is super helpful!!

  • @MrTommycat95
    @MrTommycat95 3 года назад +2

    Some folks are intelligent and smart but are horrible at teaching. Corey is smart, intelligent and born to be a teacher. While I am going to contribute on patreon right away, you have a gift that you can use to sell your videos at a small price to benefit and educate the population. Amazing

  • @gokiburi9
    @gokiburi9 2 месяца назад +2

    very easy to understand :) thank you!!

  • @thrilochanpakkapoti99
    @thrilochanpakkapoti99 2 года назад

    After seeing one video, i am addicted to watch more. Thank you friend

  • @yogi30303
    @yogi30303 3 года назад

    Man, you're awesome. You made everything sound so easy.

  • @hackpens2246
    @hackpens2246 2 года назад

    Fantastic video. I learnt some great options today. Thank you very much!

  • @RahulDubey121
    @RahulDubey121 2 года назад

    Another awesome video from one of the greatest online tutors.. Hats off, corey. With lots of Love from India :)

  • @soumitripattnaik
    @soumitripattnaik 6 лет назад +27

    These days I hit like as soon as I click on the video, I know it's going to be awesome anyway :)

  • @arborinfelix
    @arborinfelix 4 года назад

    This was very informative. Thank you for the video.

  • @sekander1253
    @sekander1253 3 года назад

    Excellent tutorial! Thanks a ton for sharing.

  • @kenchiken6338
    @kenchiken6338 Год назад

    This video is definitely getting saved for future use

  • @andresriffo4036
    @andresriffo4036 6 лет назад +1

    Just AMAZING! Thank You!!

  • @tamirsasi
    @tamirsasi 3 года назад +1

    The video is excellent, very clear, I learned a lot

  • @techwithshudarsan559
    @techwithshudarsan559 2 года назад

    It was helpful for me. Thank you

  • @nappingyiyi
    @nappingyiyi 2 года назад

    thank you so much for talking about the BSD grep and GNU grep!! i stuck there for so long ;-;

  • @hanac5586
    @hanac5586 Год назад

    Wonderfully explained

  • @moha_linus
    @moha_linus 5 лет назад +2

    I'm really so happy beacause i found this channel
    Ur the best wallh ... sorry for my bad english

  • @arunsinghchouhan5541
    @arunsinghchouhan5541 4 года назад +1

    Nicely explained. Thanks!

  • @falkelh
    @falkelh 2 года назад

    I really like your shells theme! Its also a great tutorial!

  •  5 лет назад +30

    He's really an amazing guy. I watch this even I know this. So addicted.
    Suggestion: put an xargs video :-)

    • @filthyE
      @filthyE 5 лет назад +1

      Good suggestion! xargs is so useful!

  • @genericusername555
    @genericusername555 5 лет назад +2

    Excellent tutorial.

  • @jamesyen98
    @jamesyen98 3 года назад

    This is very helpful, thank you very much!

  • @subhamraoniar5180
    @subhamraoniar5180 2 года назад

    Amazing video, exactly what I wanted

  • @cwash08
    @cwash08 6 лет назад +4

    Nice tutorial, I see there''s also a find tutorial too. I'll check it out. I always am confused between both of them

  • @sabitkondakc9147
    @sabitkondakc9147 2 года назад

    it was rather helpful, great thanks for the contents.

  • @andylib
    @andylib 5 лет назад +1

    A video of pure perfection

  • @tomaspyth7017
    @tomaspyth7017 5 лет назад +5

    Hi corey, well done like always 👍👍 thanks
    Nevertheless i would like to add a trick if you didn't already know that
    When you use history and grep you could wrap the g of grep in a square braquets in order to not get the command itself in the output of the matched results...
    History | [g]rep

  • @MariaFlorenciay
    @MariaFlorenciay 5 лет назад +3

    Very well explained! :D

  • @spot1401
    @spot1401 6 лет назад +5

    Coincidentially, I had just tried out grep yesterday after completing the "Terminus" game. Today my colleague was very impressed when in a matter of seconds, out of 7500 case files, I picked those 40 or so which contained one certain word. also you can export the results easily into a file (I use &>>filename.txt (.csv also works)), which might come in handy if your boss wants "all the contracts with the Miller Company ASAP", or if you want to quickly mail a list of relevant files. As always, great video!

    • @coreyms
      @coreyms  6 лет назад +5

      Nice! Yeah, knowing the command line is a great way to do tasks like this and is a lot more time efficient than writing a complete program from scratch to do the same functionality.

    • @spot1401
      @spot1401 6 лет назад +2

      I think back to the days where I literally let Windows XP search through "all .doc files, look for existence of expression Blabla" over the whole FRIGGIN WEEKEND! I think back in shame of course :) One day, I will make a video explaining how I turned an unsorted mess of 15 years unsorted .doc files into a searchable database over a weekend and I will refer a lot to you. Thanks man!

    • @midokoudaih290
      @midokoudaih290 5 лет назад +1

      This is exactly what I'm looking for, a way to search for a certain word within 10-20K of case files, located on different drives. I usually use mdfind "word" but it doesn't always work on pdf files, do you mind sharing that method/command you used to find those files?

  • @iandthopper
    @iandthopper 4 года назад +1

    Corey is simply the best.

  • @TJKhara
    @TJKhara 3 года назад +1

    Thank you great video!

  • @shubho5das
    @shubho5das Год назад

    Brilliant, thank you!

  • @majki5900
    @majki5900 3 года назад

    awesome tutorial, full of details. Thanks for that ! Subscribed ;)

  • @benwalsh2825
    @benwalsh2825 5 лет назад +3

    Great video as always. Our company has switched from Windows to Mac, and I find all of these videos supremely helpful while transitioning.
    Also, I find it interesting that Gnu is pronounced Gah-new when referring to the software, but just "New" when referring to the animal; sort of like Dvorak the composer (pronounced: d(ə)-VOR-zha(h)k) vs Dvorak the professor/keyboard designer I guess. Thanks again!

    • @coreyms
      @coreyms  5 лет назад +2

      Glad you find the videos helpful! As far as the pronunciation, if you're interested there's a short clip on this site with the author explaining how he came out with the pronunciation. Kind've humorous and interesting:
      www.gnu.org/gnu/pronunciation.en.html

    • @benwalsh2825
      @benwalsh2825 5 лет назад

      @@coreyms Well that is really cool! Thank you for sharing it! Gnu has always been my favorite word choices when playing Hangman with folks for the first time. Almost always wins. :)

  • @goddardpk
    @goddardpk 3 года назад

    Hi Corey, thanks for last bit on Mac BSD grep distinction!

  • @renergoncalveslopes
    @renergoncalveslopes 2 года назад

    You're the best! Thanks again.

  • @PoeLemic
    @PoeLemic 4 года назад +1

    Thanks for covering this. Man, do you make things understandable and simple. I wish that I would have just used RUclips to learn Linux, instead of doing a community college course.

  • @experimentalhypothesis1137
    @experimentalhypothesis1137 4 года назад +1

    best as always. your videos are superuseful

  • @user-uu1bx4xv1s
    @user-uu1bx4xv1s 3 года назад

    you saved my day sir, thank you so much

  • @LuisJimenezr01
    @LuisJimenezr01 5 лет назад +3

    YOUR CONTENT IS SO UNDERRATED!! THANK YOU SO MUCH FOR YOUR HELP!!

  • @abdelazizabdelioua890
    @abdelazizabdelioua890 5 лет назад +2

    Continue adding courses, you are awesome man, watching your videos makes it both enjoying and learning

  • @brpawankumariyengar4227
    @brpawankumariyengar4227 4 года назад +1

    Great video ... thank you

  • @samkotha1645
    @samkotha1645 5 лет назад +3

    awesome explanation tq sir

  • @Luvxaurora
    @Luvxaurora 2 года назад

    Very nice never bothered to learn it before but great video

  • @nassav3
    @nassav3 6 лет назад

    Awesome work as usual, Mr Schafer! Can you make a python tutorial on big data in the future? Would be really interesting!

  • @digitalaks
    @digitalaks 6 лет назад +1

    Great video... You could have mentioned about grep -v option too.

  • @manuelapostol7664
    @manuelapostol7664 4 года назад +1

    THANK YOU SO MUCH

  • @martintouko8359
    @martintouko8359 2 года назад

    fantastic thanks . god bless man!!!

  • @ghost31313
    @ghost31313 Год назад

    thank you very well done

  • @HSfox
    @HSfox 3 года назад

    This made so much sense :D

  • @MrJaylassiter
    @MrJaylassiter 4 года назад +1

    Thank you!

  • @patriciamirelladasilvascar1011
    @patriciamirelladasilvascar1011 3 года назад

    That's a great video!

  • @JAWang1994
    @JAWang1994 Год назад

    great explanation

  • @markslima1557
    @markslima1557 4 года назад +1

    Finally a great explanation of GREP for Mac terminal nerds like me! GOLD!

  • @maspoetry1
    @maspoetry1 4 года назад

    great tutorial, thanks!
    Not sure if you did it purposely but -win is an easy, useful flag to remember

  • @Lumary
    @Lumary 4 года назад +1

    awesome,thank you! :)

  • @SanaAliM
    @SanaAliM 4 года назад

    Thank you for this very amazing and concise tutorial. You have summarized everything perfectly! Does . and ./* mean the same thing if I do grep r?

  • @hedleypanama
    @hedleypanama 6 лет назад +3

    I thinkl you forgot the -v option that matches everything but the pattern!
    Anyway, I learn a lot! thanks for your nice video!

  • @aravind4444
    @aravind4444 4 года назад +1

    really useful stuff

  • @GlobalYoung7
    @GlobalYoung7 2 года назад

    Thank you 😊

  • @BrendanMetcalfe
    @BrendanMetcalfe 4 года назад +1

    Thanks!

  • @user-bk8en4fm7i
    @user-bk8en4fm7i 3 года назад

    very helpful

  • @sam2223
    @sam2223 3 года назад

    your videos are great

  • @Gaplix
    @Gaplix 5 лет назад +3

    i luv this guy

  • @rajivraghu9857
    @rajivraghu9857 5 лет назад +1

    Well made stuff..

  • @ilgas11
    @ilgas11 3 года назад

    the only youtuber to speak at playback speed 1.5 by default! :D

  • @rotamagzine
    @rotamagzine 6 лет назад +3

    You are the best

  • @wetwinz5905
    @wetwinz5905 3 года назад

    Good job bro

  • @tomfogle8173
    @tomfogle8173 5 лет назад +1

    Hey love the video; got a question.
    Homebrew decided to deprecate the --with-default-names option and I am having trouble finding how to do the same thing as you did with that now gone. Do you have any advice?

  • @nguyentanthanh7933
    @nguyentanthanh7933 2 года назад

    Thank you

  • @skinnymanua
    @skinnymanua Год назад

    Once I fell asleep on the keyboard typing grep arguments and it showed me the path to the 5th demension

  • @NikhilCherianKurian
    @NikhilCherianKurian Год назад

    Hey, thanks for the great tutorial, btw how did you create a custom zsh / bash session for theses tutorials?

  • @shrirambalaji2109
    @shrirambalaji2109 2 года назад

    Thank you....

  • @lokeshkoliparthi9268
    @lokeshkoliparthi9268 2 года назад

    For any youtube searches, If I see your video I would just open it

  • @dhanushsivajaya1356
    @dhanushsivajaya1356 3 года назад

    Thankyou sir

  • @DrownedSimo
    @DrownedSimo 3 года назад

    great video! What about sed and awk? are you ever gonna cover them? Keep it up, pretty good work ;)

  • @Lukas-wm8dy
    @Lukas-wm8dy 3 года назад +3

    In case any one is having issues with the --with-default-names flag on Mac - it is apparently not available anymore in the latest version of homebrew. One workaround that worked for me is to 1. install the package via "brew install grep"; 2. set up an alias pointing from grep to ggrep. You can do this by adding 'alias grep='ggrep' somewhere in your .bash_profile file.
    Steps:
    1. brew install grep
    2. nano ~/.bash_profile
    3. (add 'alias grep='ggrep' somewhere in the file and then save it)
    4. open new terminal for the change to become effective
    5. check with grep -V (should display "ggrep (GNU grep) ...")