I downloaded some source codes of a program and put it in a folder I want to find a function declaration from the folder on terminal, how to do it with shell command? thanks!
using grep :
grep -Hri function_name .
if you want only the path :
grep -ril function_name .
. stands for current directory
-i : case-insensitive
-r : recursive
-H : Print the file name for each match
-l : Suppress normal output; instead print the name of each input file from which output would normally have been printed.
See man grep
An interesting tool is ack, it will avoid searching in .svn, .cvs, .git dirs and such... It is designed to search code.
Example :
$ cd /usr/share/perl5
$ ack -r 'Larry\s+Wall'
site_perl/Inline/C.pm
370:# bindings to. This code is mostly hacked out of Larry Wall's xsubpp program.
core_perl/overload/numbers.pm
5:# Copyright (C) 2008 by Larry Wall and others
core_perl/CPAN.pm
876:# From: Larry Wall <[email protected]>
or just file path :
$ ack -rl 'Larry\s+Wall'
vendor_perl/LWP.pm
site_perl/Inline/C.pm
core_perl/overload/numbers.pm
core_perl/CPAN.pm
core_perl/SelfLoader.pm
core_perl/AutoLoader.pm
core_perl/AutoSplit.pm
core_perl/Test/Harness.pm
core_perl/XSLoader.pm
core_perl/DB.pm
No need the ending . with ack (compared to grep)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With