Reputation: 1003
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!
Upvotes: 11
Views: 22002
Reputation: 371
Try using CScope. You also need to have vi/vim installed.
After you install it, just run the following command in the folder you want to find the function:
cscope -R
After that, a menu will appear, showing many options to find all symbols, the function definition, functions which calls the function, etc.
Upvotes: 2
Reputation: 185035
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
)
Upvotes: 17
Reputation: 15397
This will go through all the files in the directory you opened and any subdirectories (though it messes up if there are spaces in a file or directory name), will search all of them for the FUNCTION that you put, and will output the path to the file and show the matching line. Run it by cd
ing to the directory you opened, (and replace FUNCTION with the function you're looking for).
find . -type f | xargs grep FUNCTION
Upvotes: 0