Find the answer to your Linux question:
Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By mizzle
I've just been playing about with Grep and Less / more in the shell. I've only recently been using Linux so there have been a fair few 'why can't I ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie
    Join Date
    Mar 2014
    Posts
    133

    Grep... Less / More etc....


    I've just been playing about with Grep and Less / more in the shell. I've only recently been using Linux so there have been a fair few 'why can't I just xyz' moments, and I'm sure there're more to come...

    But using these commands together with a few C files that I'm working on has been nice this afternoon...

    Just thought I'd say thank's to the help I've received here so far... looking forward to learning more.

  2. #2
    Linux Engineer
    Join Date
    Apr 2012
    Location
    Virginia, USA
    Posts
    917
    I love grep. It's one of my favorite things about Linux. Using grep to search through a directory full of files on Linux will inevitably lead to a few 'why can't I just xyz' moments when you go back to Windows to do the same task, lol.

  3. #3
    Linux Newbie
    Join Date
    Mar 2014
    Posts
    133
    ah you can grep whole folders? Nice....Yeah it seems like a handy little tool! I haven't had much use as I'm only learning both Linux and C at the moment...so the programs are tiny

    But yeah, the reason I'm learning Linux at the same time is that I view the computer as another tool really, and being able to control it can only be a bonus. Although I'm fairly au fait with Windows It's all been through GUI stuff and out side of the buttons I'm provided there's not much I can do!

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Engineer
    Join Date
    Apr 2012
    Location
    Virginia, USA
    Posts
    917
    Sure can. Just navigate to a folder with a bunch of text files, and grep away:
    grep "some text" *
    You'll get a handy output for each occurrence:
    grep "hello" *
    file1.txt:hello
    file2.txt:hello

    Very useful when you're trying to find something in someone else's code (like where a function is defined) without having to trace things through multiple files.

  6. #5
    Linux Engineer docbop's Avatar
    Join Date
    Nov 2009
    Location
    Woodshed, CA
    Posts
    949
    When I worked at Borland Developer Support one of the two lines we told usually noob developers "grep is your friend". They'd want to know about a function we tell them you got all the header files and copy of grep find your answer. Okay the other saying.... When they would ask about one of our libraries we included source code to we'd say in our best Darth Vardar voice "use the Source Luke!".

    Another tool to get used to is diff for comparing files especially if you been make changes to config files (assuming you make a copy of the prevous one or use something like GIT on your /etc.

  7. #6
    Linux Newbie
    Join Date
    Mar 2014
    Posts
    133
    Quote Originally Posted by docbop View Post
    They'd want to know about a function we tell them you got all the header files and copy of grep find your answer.
    Nice... just grep the header file for the function name and read the source code around it?

    Another tool to get used to is diff for comparing files especially if you been make changes to config files (assuming you make a copy of the prevous one or use something like GIT on your /etc.
    Don't know what I'd do with it yet... I haven't used GIT before although It'll be on the to-do list at some point I'm sure

    I'm still learning how to learn TBH!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •