Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I've used these so much:

    function gc() { grep -rnI "$@" * ;}
    function gcA() { grep -rnI -A 5 "$@" * ;}
    function gcB() { grep -rnI -B 5 "$@" * ;}
    function gcC() { grep -rnI -C 5 "$@" * ;}
    function gcf() { grep -rnIl "$@" * ;}
Just helper functions built on top of grep


And what do they do? It's not obvious.

edit: Thank you both!


-r enables recursion

-n enables line numbers

-I (eye) ignores matches on binary files

-l (ell) lists the filenames of matching files only (overrides -n)

-A, -B, and -C specify how many lines of context after, before, or around the match to display.

"$@" adds any additional command line arguments passed to the functions.

* selects all the files and directories in the current directory.

So, without other arguments, the first four functions list matches with line numbers for all files (ignoring binary files) in the current directory and below, with 0 lines context (match only), 5 lines context after, 5 lines context before, and 5 lines context around the match respectively. The final function lists the filenames only and provides no context or line numbers.


-r searches directories recursively instead of single files; -n displays line numbers; -I ignores binary files. -A, -B, -C, and -l set how much context is shown: 5 lines of content before the match, after the match, or both; or just the filename and no content.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: