Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Grep how to find files based on file contents in UNIX     - Django url () function Detailed (Programming)

- Modular JavaScript (Programming)

- Create several practical points of high security PHP site (Linux)

- How to use the Linux command compress JPEG images (Linux)

- Getting Started with Java NIO (Programming)

- A deep understanding of Java enum (Programming)

- Install Ubuntu 14.04 and Windows 8 / 8.1 dual-boot in UEFI mode (Linux)

- Multi-core CPU, multi-threading and parallel computation (Linux)

- Linux basic introductory tutorial ---- regex basis (Linux)

- sed and awk in shell usage and some examples (Linux)

- Use Docker containers (Linux)

- Storm how to assign tasks and load balancing (Programming)

- Java reflection by calling the class method (Programming)

- Denyhosts prevent hackers using SSH scanning (Linux)

- 2 minutes to read large data framework Hadoop and Spark similarities and differences (Server)

- Linux memory management (Linux)

- Preliminary understanding of SELinux security management (Linux)

- Linux disk partition, format, mount the directory (Linux)

- Do you know how to build the Linux kernel (Programming)

- CentOS 6.6 x64 Oracle Database 11gR2 RAC automated installation scripts (Database)

 
         
  Grep how to find files based on file contents in UNIX
     
  Add Date : 2018-11-21      
         
         
         
  To complete the course work, I write a lot of C language code and save them as /home/user/c/*.c and * .h. Then the UNIX shell window How can I pass a string or a word (for example, the function name main ()) contents of the file to find the file it?

You will need the following tools:

[A] grep command: output matching model line.

[B] find command: find files in the directory hierarchy.

 

Use the grep command to find files based on content

Enter the following command:

grep'string '*. txt
grep'main ( '*. c
grep '# include ' *. c
grep'getChar * '*. c
grep-i 'ultra' *. conf
grep-iR 'ultra' *. conf
among them

-i: ignore patterns (matching string valid, VALID, ValID) and the input file (matching file.c FILE.c FILE.C) case.
-R: Recursively read all files in each directory.
 

Highlight to match the pattern

Searching for a large number of files when you can easily highlight mode:

$ Grep - color = auto-iR 'getChar ();' * c.
 

It displays the file name and line number to find patterns

You may want to display the file name and line number:

$ Grep - color = auto-iRnH 'getChar ();' * c.
among them,

-n: in front of each line of output is added to the beginning of the line number 1.
-H: Print filename for each match. To search for multiple file This is the default option. (LCTT Annotation: -h option forces hide filenames; additional -l and -L option to display only matches / does not match the file name, and -H and -h for controlling the front display matching lines display / not display file name, note the distinction.)

$ Grep --color = auto-nH 'DIR' *

You can also use the find command:

$ Find.-name "* .c" -print | xargsgrep "main ("
     
         
         
         
  More:      
 
- Oracle 11g statistics collection - collection of multi-column statistics (Database)
- Puppet 3.5 Source package Installation and Configuration (Server)
- MySQL stored procedures and triggers (Database)
- Oracle 11g RAC root.sh execution error second node failure example (Database)
- Introduction Linux namespace (Linux)
- How to understand Python yield keyword (Programming)
- How to interactively create a Docker container (Server)
- Ubuntu under VirtualBox virtual machine serial port settings (Linux)
- PostgreSQL query lock and kill the process (Database)
- Handle large data problems Bit-map method (Programming)
- Binary search -Java achieve (Programming)
- Use Bosh deploy CloudFoundry problems encountered on OpenStack (Server)
- Linux text processing tool of awk (Linux)
- C ++ stderr / stdout redirected to a file (Programming)
- Linux Getting Started tutorial: XWindow what (Linux)
- ORA-600 [kcbz_check_objd_typ] Error Handling (Database)
- MySQL main and backup replication structures (using mysqld_multi) (Database)
- Java implementation linear table - represents the order of representation and chain (Programming)
- AngularJS notes --- Scope and controller (Programming)
- Linux operating tips: Can not open file for writing or operation not permitted solution (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.