Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to find a function from a folder on linux

Tags:

linux

grep

shell

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!

like image 384
user138126 Avatar asked Mar 28 '13 23:03

user138126


1 Answers

Try doing this

using grep :

grep -Hri function_name .

if you want only the path :

grep -ril function_name .

Explanations

  • the trailing . 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

Last but not least

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)

like image 132
Gilles Quenot Avatar answered Oct 10 '22 20:10

Gilles Quenot