Zhanhailiang Date: 2014-10-11
Background
There are a number of handy graphical tools under window to enable global search, but linuxserver is a higher threshold because of the use of command-line operations.
The first of these methods
First, For the simplest example, we often need to look at the definition of a function while reading the code, but the general open source project code is quite large, and you can use Find+grep to easily find the definition of the function, for example, below. I want to search the PHP source code for the definition of the Is_array method. For example, the following:
[[email protected" standard]# Span style= "COLOR: #ff0000" >find. -name ' *.c '-exec grep-hna ' Is_array ' {} \; ./basic_functions.c:2540:zend_begin_arg_info (Arginfo_is_array, 0)./basic_ Functions.c:3049:php_fe (Is_array,arginfo_is_array)./type.c:283:/* {{{proto bool Is_array (mixed Var)./type.c:285: Php_function (Is_array)
Here are two points to note: 1. Find when using-exec ";" is required, such as the following two methods will cause "find:missing argument to '-exec '", in which the first command error is due to the fact that ";", while the second command error is due to run the statement in the Shell ";" It is thought to be a terminator, not a-exec, so it must be escaped when used.
[[email protected" standard]# find-name ' *.c '-exec Grep-hna ' Is_array ' {} find:missing argument to '-exec ' [[email protected" standard]# find. -name ' *.c '-exec grep-hna ' Is_array ' {}; find:missing argument to '-exec '
[[email protected] standard]# find--help actions:-delete-print0-printf format-fprintf FILE format-print -FPR Int0 file-fprint File-ls-fls file-prune-quit -exec command;-exec command {} +-OK command; -execdir command;-execdir command {} +-okdir command;
2. As in the above example, when using grep, I added-hna, which output file path, line number, and corresponding text content:
[email protected] standard]# grep--help -N,--line-number print line number withoutput LINES --line-buffered flush output on every line -H, --with-filename print thefilename for Each match -A, --text equivalent to--binary-files=text
A different approach
Given the need to view the source code for a view project, it would be perfect to install the Ctags tool on the server to match vim, please refer to the "Sublime Text 2 installation ctags plug-in" similar principle to install the configuration on Linux, Strong technical flow of students using this method.
Perfect use of Find+grep for global code search under Linux