grep: A Practical Guide

Sdílet
Vložit
  • čas přidán 16. 01. 2024
  • A quick guide on getting better with grep and its more popular uses.
  • Věda a technologie

Komentáře • 156

  • @buysnoah
    @buysnoah Před 4 měsíci +288

    Who up grepping they file rn

  • @amandasandell3351
    @amandasandell3351 Před 4 měsíci +70

    now THIS is the kind of tutorial video i'd like to see more often. Straight to the point, no boilerplate, explain a concept and show an example. Very educational and useful

    • @navekeng
      @navekeng  Před 4 měsíci +4

      Thanks! I appreciate it, more to come 😄

  • @leonardofralini6398
    @leonardofralini6398 Před 4 měsíci +33

    No useless talks, great content with examples, good video and audio quality.
    Nice job! You earned a sub
    Keep it up!

  • @diceandbricks
    @diceandbricks Před 3 měsíci +8

    I like how you focus on a single command and give a very helpful overview. So many other "10 great linux commands" videos don't give enough detail for me to retain them. This is much better.

  • @Nobody-eg4bi
    @Nobody-eg4bi Před měsícem

    You have the best video ever about grep on CZcams

  • @TreeLuvBurdpu
    @TreeLuvBurdpu Před 3 měsíci +3

    -C is for context, a very important word.

    • @navekeng
      @navekeng  Před 3 měsíci +2

      Yea haha just chugging through forgot the word ha

  • @jwf3148
    @jwf3148 Před 3 měsíci +1

    I'm pressured for time, so I can't "Like" all of the positive comments - but please note that I do agree with each and every one...VERY userful videos...Yea for us, Thank you to you.

  • @abhishekvenkat9585
    @abhishekvenkat9585 Před 3 měsíci

    Honesty I have known grep for like a decade and use it literally daily for half of that decade but watching this made me realise what all I was missing on. Thanks for the video.

  • @florianrose8907
    @florianrose8907 Před měsícem

    Please keep making those Videos. Those are so nicely done :) I am thankful!

  • @monkeecrap
    @monkeecrap Před 3 měsíci +5

    You absolute gigachad. This was amazing, thank you. 🙏

    • @navekeng
      @navekeng  Před 2 měsíci +2

      Glad you enjoyed it!

  • @muhammedkadirtan3469
    @muhammedkadirtan3469 Před 4 měsíci +9

    Came for the grep, stayed for the regex. Great content. One thing I would add is, sometimes I grep twice. For example, I want to find all the 404 logs, but then I also want to filter out logs with specific message, say "user not found". Then I can: cat server.log | grep 404 | grep 'user not found'

    • @navekeng
      @navekeng  Před 4 měsíci +2

      Ah good point, Yea I guess it’s not obvious haha
      Thanks for watching!

    • @Hornet1806
      @Hornet1806 Před 3 měsíci +1

      Pretty sure you can do both of those at the same time with -E and/or -v. Also, you can pass your file in to grep directly rather than cat, which is for concatenating files together. On some shells you can also just < file to print its contents.

  • @abneryang2102
    @abneryang2102 Před 3 měsíci +2

    Just found this channel, great stuff. I really like the way you go about explaining stuff. Looking forward to looking through more of your content - keep going!

    • @navekeng
      @navekeng  Před 2 měsíci +1

      More on the way, thanks!

  • @danel1922
    @danel1922 Před 2 měsíci

    such a great concise video, thx!

  • @codeman99-dev
    @codeman99-dev Před 3 měsíci +1

    Very important note! The grep command is very battle tested.
    A regex that is safe with grep is not necessarily safe to use on requested resources. Always use extra caution with unknown inputs. Use extra extra caution if that unknown input can build a regular expression!

  • @hasib927
    @hasib927 Před 4 měsíci +7

    Really loved the video, very comprehensive yet quite short. Please keep posting more videos.
    Two useful flags that I would've love to see: -R and -n.

    • @navekeng
      @navekeng  Před 4 měsíci +2

      good points, I didn't touch -n and I ended up cutting -R for time and brevity
      but there is a good point for its importance and should of figured out how to fit it in

  • @thewadegreen
    @thewadegreen Před 4 měsíci +4

    I subbed when he said "the alligators", hilarious! Loving the helpful video, it's great how you break everything down so well step by step.

    • @navekeng
      @navekeng  Před 4 měsíci +3

      LOLOLOLOL
      Talking and typing is hard enough... to much to handle saying 'angle bracket' hahaha

    • @navekeng
      @navekeng  Před 4 měsíci +3

      and of course thanks!

  • @niczoom
    @niczoom Před měsícem

    Great video, thanks!

  • @ericpayne2846
    @ericpayne2846 Před 4 měsíci +9

    Excellent content. I hope you make a ton of videos this year. Thanks for sharing your knowledge!

    • @navekeng
      @navekeng  Před 4 měsíci

      That's the plan! thanks!

  • @INCLASKY
    @INCLASKY Před 4 měsíci +4

    Awesome videos for people learning man, keep it up!

    • @navekeng
      @navekeng  Před 4 měsíci +1

      Glad you like them!

  • @sagarchilivery6112
    @sagarchilivery6112 Před 4 měsíci +9

    Trust me, you will grow like anything just keep posting linux videos! totally loving it!

  • @HamsterLover1337
    @HamsterLover1337 Před 2 měsíci

    Amazing!

  • @ekinakkaya9257
    @ekinakkaya9257 Před 4 měsíci +2

    straight to the point, also i really like the video & sound quality. you earned a subscriber brah

  • @JohnSmith-ni4cs
    @JohnSmith-ni4cs Před 3 měsíci

    @4:40 -e tells grep to search for the regular expression '-a'. It does not negate special characters. For example if you searched for -e 'a$' it would return lines ending with the letter a

  • @jenselstner5527
    @jenselstner5527 Před 4 měsíci +5

    Use 'grep -P' for Perl regexes. Then you're able to use special shortcuts like \d for a digit or \s for a whitespace, etc.

    • @navekeng
      @navekeng  Před 4 měsíci +1

      Yea I avoided Peral because I think it adds complexity to what is necessary vs not, hell I was trying to avoid -E but then the command was so ugly lol
      my thought was the Perl folks already know how to do Peral regex! lol

    • @navekeng
      @navekeng  Před 4 měsíci

      Thanks for the suggestion and watching!

  • @harijagarnauth
    @harijagarnauth Před 3 měsíci +1

    Awesome!

  • @abhishektiwari9561
    @abhishektiwari9561 Před 3 měsíci +2

    this is a great short and to the point video.

  • @ShinichiroKururugi
    @ShinichiroKururugi Před 3 měsíci

    Great video! I consider myself a bit of a seasoned sysadmin but I still managed to learn '-w' and '-e' for the first time! I normally use 'fgrep " term " ' (or 'grep -F') to search literal strings.
    As a bit of feedback, I would avoid teaching 'cat | grep' as an example because it is generally considered to be poor practice as it achieves the same result while expending more CPU resources. But if you must use the example, then at the very least mention that it is less than an ideal use 'cat'. While 'cat' itself is not a huge deal resource-wise, myself, a long time ago have been guilty of using 'cat | grep' not knowing any better but hope to teach others better practices and better habits. I would instead use different commands like 'ifconfig' or 'ps' to demonstrate the use of piping into 'grep'.

  • @JairEmanuels
    @JairEmanuels Před 4 měsíci +2

    Great video, will definitely help me prepare for my exam :)

  • @jsd4544
    @jsd4544 Před 3 měsíci

    Useful! Thanks

  • @dandogamer
    @dandogamer Před 4 měsíci +4

    Need a video on jq , I'm a noob at it but can appreciate how efficient it can be to find and manipulate json

    • @navekeng
      @navekeng  Před 4 měsíci +3

      No joke writing out a vid on jq right now!

    • @navekeng
      @navekeng  Před 4 měsíci +3

      Sometime this week actually! Haha thanks for the comment

  • @neunmalelf
    @neunmalelf Před 4 měsíci +2

    I guess that kind of videos can be helpful for beginner. Not too much detail and options digging, still a decent amount of helpful information. Well done! 👍☺

    • @navekeng
      @navekeng  Před 3 měsíci +1

      Glad you enjoyed it!
      Yea the intention is showing the power, basically removing some unknown unknowns from someone newer or rusty with the tool!

    • @neunmalelf
      @neunmalelf Před 3 měsíci

      I wonder if people would be interested in CZcams shorts with 'new / additional' tips and 'reminder' using this common tools 🤔.grep and find would be good candidates IMHO

  • @NostraDavid2
    @NostraDavid2 Před 4 měsíci +2

    RE: Logging
    Use structured logging and preferrably JSON - you can now use jq and do WAY more powerful stuff in an almost-as-complex language as regex.

    • @navekeng
      @navekeng  Před 4 měsíci

      Yea that is true, I have a whole vid in the pipeline on OpenTelemetry (my day job is on an Observability team fun fact)
      But maybe I will do a quick video on jq, imo I use jq more then like awk.
      Thanks for the input, ill call you out when I do a vid on jq lol!

  • @TrustJesusToday
    @TrustJesusToday Před 2 měsíci

    It is helpful to get a grip on grep.

  • @tanuj05
    @tanuj05 Před 4 měsíci +1

    Nice tutorial

  • @friedrichmyers
    @friedrichmyers Před 4 měsíci +4

    This is what youtube videos should be like!

    • @navekeng
      @navekeng  Před 4 měsíci

      Well don't think I can ask for a better complement! haha thank you!

  • @BarisGulten
    @BarisGulten Před 3 měsíci

    Good channel. Keep going 😊

  • @Hornet1806
    @Hornet1806 Před 3 měsíci +1

    Pretty sure -C is context. I use vim as my pager for man pages, but this should apply regardless. In man, I would use /^[ ]*-a, to find the section of the man page relating to the a flag. It reads, “show me lines beginning with some number of spaces immediately followed by -a”.

    • @navekeng
      @navekeng  Před 3 měsíci

      good point, and yea I missed context lol

  • @JassonCordones
    @JassonCordones Před 2 měsíci +1

    nothing that I didn't know already but great video anyways

  • @spamharder1757
    @spamharder1757 Před 4 měsíci +2

    One useful flag I didn't see: the -o flag. I use it a lot when grepping by some regex pattern and I only need the match output

    • @navekeng
      @navekeng  Před 4 měsíci

      Oh good callout I missed that and it would be a helpful one for sure!

  • @bermudi
    @bermudi Před 4 měsíci +2

    You should be using your pager to find things in manual pages. Usually `less` is used as man pager and literally all you have to do is press `/`

    • @navekeng
      @navekeng  Před 3 měsíci +1

      Yea makes sense, I was mostly just demoing Gregs capabilities here but I could have been more clear it’s one of the ways to do it not “the” way.
      Thanks for watching

  • @bl00dspec75
    @bl00dspec75 Před 3 měsíci +1

    grep is probably one of the most powerful pieces of software ever created next to git

  • @acayipbiseyya
    @acayipbiseyya Před 2 měsíci

    thx man

  • @surplusvalue3271
    @surplusvalue3271 Před 4 měsíci +1

    super underrated

  • @0xchilli
    @0xchilli Před 4 měsíci +1

    take the sub bro , u deserve it , will recommend u a lot

  • @emilne83
    @emilne83 Před 3 měsíci

    Great video overall.
    But I just want to point out that last part about filtering out IPs is wrong. The first 3 octets can all be 1-3 digits. That filter will miss a lot of possible IPs.

  • @nikolaygruychev2504
    @nikolaygruychev2504 Před 4 měsíci

    damn i did not know some of the flags. nice vid man

    • @navekeng
      @navekeng  Před 4 měsíci

      Glad It was helpful, thanks for watching

  • @tieTYT
    @tieTYT Před 4 měsíci +2

    I've always thought "-C n" stands for context. As in, the number of lines of context around the match. At least, that's how I remember it.

    • @navekeng
      @navekeng  Před 3 měsíci

      Ngl I made up contains clearly haha you are prob right I need to check the man page haha
      Thanks for the spot haha

  • @jvdl-dev
    @jvdl-dev Před 4 měsíci +1

    I know this wasn't the point of your video, but when you're using `man` pages, usually your pager can perform searches within by pressing `/` while you're looking at the man page. For example `/` followed by `-D` and then pressing Enter will find the `-D` flag and then press `n` or `N` to search forwards and backwards. (You can also press `?` instead of `/` to start searching backwards. If you spend a lot of time in man pages, definitely worth figuring out the keyboard shortcuts :)
    Loved the video btw, very to the point, no unnecessary preamble, just pure usefulness.

    • @navekeng
      @navekeng  Před 3 měsíci +1

      Yea good point and something I could have clarified that this was one way to do it not “the” way to do it!
      Thanks for the comment and watching!

  • @devondecenzo2658
    @devondecenzo2658 Před 3 měsíci +1

    Wow; just found this and loved it! Thanks Navek, you know have a new Sub... ME :)

  • @MaxBerson
    @MaxBerson Před 3 měsíci +1

    6:00 C for "circa"!

  • @callisoncaffrey
    @callisoncaffrey Před 3 měsíci

    If you're using Gnu grep at least make use of the -P switch to get access to the Pearl regex. Also you could have mentioned that not all distros have --color added to the grep alias. Your IP regex isn't fully accurate either, since it also would match illegal addresses.
    Everything else was quite nice though. For coding purposes -Rn is useful (recursive and show line number). If you want to compare files I found it helpful to add the -x switch. I usually compared kernel .configs with grep -xivf old.config new.config, though I found that still needs too much scrolling, so I hope you have a gnu awk video ready, and you better not pipe grep into awk!

  • @hj45lp
    @hj45lp Před 3 měsíci

    I suggest you watch next the fantastic "Where GREP came from" by Computerphile...

    • @navekeng
      @navekeng  Před 2 měsíci +1

      A great video for sure

  • @arief_
    @arief_ Před 4 měsíci +1

    the nice thumbnail drag me here

    • @navekeng
      @navekeng  Před 4 měsíci

      Weirdly enough this might be the best complement I have gotten, I try so hard and feel so damn bad at creating thumbnails.
      Honestly Linux is the easy part lol,
      Thanks!

  • @SamClegg
    @SamClegg Před 3 měsíci +1

    For `-C` the mnemonic is "context" I believe

    • @navekeng
      @navekeng  Před 3 měsíci +1

      yea correct! hahaha I was flying through it and forgot what it was lol

    • @SamClegg
      @SamClegg Před 3 měsíci +1

      @@navekeng awesome videos by the way.. should have said that part first :)

    • @navekeng
      @navekeng  Před 3 měsíci

      Thanks! Haha

  • @carrion1234
    @carrion1234 Před 4 měsíci +1

    what console font is that?

    • @navekeng
      @navekeng  Před 4 měsíci +1

      JetBrains Mono Nerd Font

    • @carrion1234
      @carrion1234 Před 4 měsíci +1

      @@navekeng oh damn, i use jetbrains mono in my jetbrains IDE, no wonder that tickled something in my brain :D thx!

    • @navekeng
      @navekeng  Před 3 měsíci

      Haha idk it’s not perfect and I don’t love it exsactly yet, but can’t find something better.
      I’m sure it will change again 😆

  • @chyldstudios
    @chyldstudios Před 3 měsíci +2

    ripgrep > grep

    • @navekeng
      @navekeng  Před 2 měsíci

      don't disagree, but you have to learn the rules before you can break them.
      Also you might not always be on a system that has ripgrep

  • @matthewrease2376
    @matthewrease2376 Před 3 měsíci

    5:25 no, I don't believe the -- could relate to bash, that would have to be a feature of GREP itself. Because all arguments are passed the same way (argv). It would have to be GREP seeing the -- and handling it to change the behavior of future arguments.

    • @rabbitt1751
      @rabbitt1751 Před 3 měsíci +1

      I’m pretty sure that “-“ is handled by libc, or more specifically getopt and getopt_long (both functions implemented in libc), which grep likely uses for parsing command line args.

  • @patrickhawk6058
    @patrickhawk6058 Před 4 měsíci +1

    grep -ril

  • @logangrosz6529
    @logangrosz6529 Před 3 měsíci

    It may be worth nothing the globbing is performed by the shell, not grep. It is equivalent to just listing all the files that match the glob (because that's literally what the shell does).

    • @navekeng
      @navekeng  Před 3 měsíci

      Yea, makes sense. Sometimes i zero in on how to use the tool and have to cut context. Its a balance for sure that I am still learning

  • @0xchilli
    @0xchilli Před 4 měsíci +1

    less, greater than are called angle brackets in this context 9:27

    • @navekeng
      @navekeng  Před 4 měsíci

      LOL I was movinnn okay... grep makes my brain fog up and I prefer "big alligator" anyways

  • @MasterSergius
    @MasterSergius Před 3 měsíci

    Like who searched for this video using grep

  • @pabloqp7929
    @pabloqp7929 Před 3 měsíci

    ripgrep®

    • @navekeng
      @navekeng  Před 3 měsíci

      ripgrep is night and day better but you can't always guarantee you have access to it as an engineer on a remote system or lets say in a troubleshooting interview!

  • @docmalitt
    @docmalitt Před 4 měsíci

    back to school kids... (btw just pumping your engagement, disregard the word salad coming out of my brai... "there is no spoon Neo"... keyboard)

    • @navekeng
      @navekeng  Před 4 měsíci

      A keyboard warrior if you will, fightin the good fight

  • @nomandates9186
    @nomandates9186 Před 4 měsíci +1

    video bookmarked

  • @roganl
    @roganl Před 4 měsíci +2

    Clear screen is Ctrl-L .

    • @navekeng
      @navekeng  Před 4 měsíci

      Somthing something “old habits” haha 😂

  • @hexssoulld
    @hexssoulld Před 3 měsíci

    Why use Grep?
    Reply with what you use it for!

  • @rabbitt1751
    @rabbitt1751 Před 3 měsíci

    `grep EXP FILE` > `cat FILE | grep EXP`

  • @lylestavast7652
    @lylestavast7652 Před 4 měsíci

    Been grepping since 1987 or so...

  • @sense3d
    @sense3d Před 3 měsíci +1

    Great, but please speak more slowly.

  • @delqyrus2619
    @delqyrus2619 Před 4 měsíci +2

    0:50 what a cat abuse.

  • @LarsBahner
    @LarsBahner Před 3 měsíci +1

    We've been trying to get people stop doing cat |grep for years. Why on earth would you do that? You add another process to your pipeline for absolutely no other reason than adding unneeded complexity. You should probably think before you try to teach.

  • @mariusfacktor3597
    @mariusfacktor3597 Před 3 měsíci +1

    I find myself needing to find a word in a directory and wanting to know the line number. -r for recursive, -n for line number
    grep -r -n searchterm dir/

  • @adriansrfr
    @adriansrfr Před 3 měsíci

    I find ripgrep to be faster and more useful, especially combined with fzf.

  • @ethernet764
    @ethernet764 Před 4 měsíci +1

    Unlocking grep: Install ripgrep 😎

    • @navekeng
      @navekeng  Před 4 měsíci +1

      “you must first know the rules, before you can break the rules” haha
      But yea if you are a power user there are many alternatives and ways to make it more powerful

  • @recarsion
    @recarsion Před 3 měsíci +1

    I use ripgrep btw

    • @navekeng
      @navekeng  Před 3 měsíci +1

      ripgrep is night and day better but you can't always guarantee you have access to it as an engineer on a remote system or lets say in a troubleshooting interview!

    • @recarsion
      @recarsion Před 3 měsíci

      @@navekeng yep, unfortunately, but GNU grep is still a great tool

  • @ThePacolicious
    @ThePacolicious Před 3 měsíci +1

    Love your content and your presentation. Got a sub from this guy. | grep "earned sub"

  • @nielsbom5558
    @nielsbom5558 Před 3 měsíci

    Give it up for grep in 2024: ripgrep. It’s faster, it auto ignores files you probably don’t want to search for and it’s mostly a dropin replacement for grep.

    • @navekeng
      @navekeng  Před 3 měsíci +1

      ripgrep is night and day better but you can't always guarantee you have access to it as an engineer on a remote system or lets say in a troubleshooting interview!