Perfect use of Find+grep for global code search under Linux

Source: Internet
Author: User
Tags sublime text

  Zhanhailiang Date: 2014-10-11
Background

There are a number of handy graphical tools for global search under window, but the use of command-line operations in Linux servers results in a higher threshold for global search.

The first of these methods

First, for the simplest example, we often need to look at the definition of a function in the process of reading the code, but the general open source project code is quite large, so you can easily find the definition of the function using Find+grep, for example, I want to search the PHP source for Is_ The definition of the array method is as follows:

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 a required parameter, the following two methods will result in "find:missing argument to '-exec '", where the first command error is due to the fact that ";" is missing, while the second command error is due to the execution of a statement in the Shell ";" is considered to be a terminator, not a-exec parameter, 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 example above, I added-hna when using grep, which output file path, line number, and corresponding text content respectively:

[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
The second method of

If the need to view the source code for viewing the project, then install the configuration on the server Ctags tools to match vim, will be the perfect solution, please refer to the "Sublime Text 2 installation ctags plug-in" Similar principle on Linux installation configuration can, strong technical flow of students use this method.

Perfect use of Find+grep for global code search under Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.