Using linux commands, is there any way to know which file has the given line of code from a given project directory?
使用linux命令,有没有办法知道哪个文件具有给定项目目录中的给定代码行?
All directories are traced recursively for all files in subdirectories as well.
对于子目录中的所有文件,所有目录都以递归方式进行跟踪。
say your project is in php
and is in directory /var/www/projectDir/
说你的项目在php中,位于目录/ var / www / projectDir /
and the line to be searched is public function getProjectData(
to know where (in which file lying in which subdirectory ) getProjectData
php function is defined?
并且要搜索的行是公共函数getProjectData(要知道getProjectData php函数定义在哪里(在哪个文件中位于哪个子目录中)?
3 个解决方案
#1
1
You can use the shell :
你可以使用shell:
grep "text string to search" directory-path -R
EDIT: adding -R
for recursive search
编辑:添加-R进行递归搜索
or even better, use PHP :
甚至更好,使用PHP:
$reflFunc = new ReflectionFunction('function_name');
print 'File :' $reflFunc->getFileName() . ' at line : ' . $reflFunc->getStartLine();`
#2
0
use the command
使用该命令
find /var/www/projectDir/ -name '*.php'|xargs grep 'public function getProjectData('
the first portion
第一部分
find /var/www/projectDir/ -name '*.php'
will search all the files which are having extension php
and within directory /var/www/projectDir
将搜索所有具有扩展名php的文件,并在目录/ var / www / projectDir中搜索
the second portion
第二部分
xargs grep 'public function getProjectData('
will search all the files found in first portion for public function getProjectData(
.
将搜索第一部分中找到的所有文件,用于公共函数getProjectData(。
xargs is used to consider the output of first portion as a standard input for second portion.
xargs用于将第一部分的输出视为第二部分的标准输入。
The symbol |
named pipe
will pipe the output to second portion
符号|命名管道将输出管道传输到第二部分
output
/var/www/projectDir/sub/directory/somephpfile.php: public function getProjectData($param1, $param2) {
now you can open the file and search for which line the content is defined using
现在,您可以打开文件并搜索使用的内容定义的行
(ctrl + F for gedit) or ( ctrl + W for nano)
or use any of your favorite editor.
或使用您喜欢的任何编辑器。
#3
0
I go with the below line. It helps me always,
我跟下面这行。它总能帮到我,
find dirname -type f -print | xargs grep -i "pattern" > /tmp/samplefile
#1
1
You can use the shell :
你可以使用shell:
grep "text string to search" directory-path -R
EDIT: adding -R
for recursive search
编辑:添加-R进行递归搜索
or even better, use PHP :
甚至更好,使用PHP:
$reflFunc = new ReflectionFunction('function_name');
print 'File :' $reflFunc->getFileName() . ' at line : ' . $reflFunc->getStartLine();`
#2
0
use the command
使用该命令
find /var/www/projectDir/ -name '*.php'|xargs grep 'public function getProjectData('
the first portion
第一部分
find /var/www/projectDir/ -name '*.php'
will search all the files which are having extension php
and within directory /var/www/projectDir
将搜索所有具有扩展名php的文件,并在目录/ var / www / projectDir中搜索
the second portion
第二部分
xargs grep 'public function getProjectData('
will search all the files found in first portion for public function getProjectData(
.
将搜索第一部分中找到的所有文件,用于公共函数getProjectData(。
xargs is used to consider the output of first portion as a standard input for second portion.
xargs用于将第一部分的输出视为第二部分的标准输入。
The symbol |
named pipe
will pipe the output to second portion
符号|命名管道将输出管道传输到第二部分
output
/var/www/projectDir/sub/directory/somephpfile.php: public function getProjectData($param1, $param2) {
now you can open the file and search for which line the content is defined using
现在,您可以打开文件并搜索使用的内容定义的行
(ctrl + F for gedit) or ( ctrl + W for nano)
or use any of your favorite editor.
或使用您喜欢的任何编辑器。
#3
0
I go with the below line. It helps me always,
我跟下面这行。它总能帮到我,
find dirname -type f -print | xargs grep -i "pattern" > /tmp/samplefile