Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Grep how to find files based on file contents in UNIX     - Linux user login and IP restrictions (Linux)

- Understand the security restore accidentally deleted critical system files (Linux)

- Linux User Rights Study Notes (Linux)

- Linux the best download manager uGet (Linux)

- To setup NOTRACK and TRACK of conntrack in iptables (Linux)

- CentOS6 5 Configure SSH password Free (Linux)

- Ubuntu 12.04 kernel configuration automatically restart and crash dump (Linux)

- Linux RPM default installation path (Linux)

- Oracle View index and use indexes Precautions (Database)

- Linux 4.0+ kernel support for hardware switching module (HW Switch Offload) (Linux)

- Oracle bdump file soaring (Database)

- Linux boot the system does not display a progress bar setting method (Linux)

- Use Ansible installation NGINX and NGINX Plus (Server)

- Arduino UNO simulation development environment set up and run simulation (Linux)

- ASM learning overview (Database)

- crontab task scheduling Health Check (Linux)

- How do I delete a NEEDS RECOVERY rollback state of undo tablespace (Database)

- Vagrant build LNMP environment (Server)

- Matters Oracle 11.2 single instance when connecting ASM need to pay attention and deal with the problem (Database)

- How to disable UEFI to install Linux on Win8 (Linux)

 
         
  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:      
 
- Manually compile Hadoop 2.6.0 under Ubuntu 14.04 (Server)
- Firewall settings oracle remote connection in Linux systems (Linux)
- IOwait Linux system monitoring diagnostic tools (Linux)
- CentOS / RedHat system partition essential requirements and partition scheme (Linux)
- Linux Platform Oracle 11g Single Instance Installation Deployment Configuration Quick Reference (Database)
- Android to determine whether the device to open WIFI, GPRS data connection (Programming)
- Sysdig: system troubleshooting tool (Linux)
- By way of a binary installation innobackupex (Database)
- shell-like program (Programming)
- CentOS6.0 successful installation and configuration OpenCV (Linux)
- Linux ban single-user mode to enhance system security (Linux)
- Connect to the Oracle Database Help class (Database)
- CentOS 6.4 (64bit) install Python 2.7.5 (Linux)
- Python virtual environment: Virtualenv (Linux)
- Ubuntu 14.04 Install WordPress on Nginx (Server)
- Ten correct use Redis skills (Database)
- Debian (Wheezy) Install Java environment / replace OpenJDK as the SUN JDK (Linux)
- Using DBMS_STAT function closes mission (Database)
- How to configure chroot environment in Ubuntu 14.04 (Linux)
- Construction CA certificate using OpenSSL command line (Server)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.