how to search for a line match from all files recursively found in a directory

veer7

Using linux commands, is there any way to know which file has the given line of code from a given project directory?

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/

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?

veer7

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

the second portion

xargs grep 'public function getProjectData('

will search all the files found in first portion for public function getProjectData(.

xargs is used to consider the output of first portion as a standard input for second portion.

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Command line to search all files in all text files in directory recursively

From Dev

How to search and remove ^M in all files in a directory recursively?

From Dev

Remove all but N files from directory recursively

From Dev

How to recursively search a directory for all files including hidden files in hidden directories, with PowerShell?

From Dev

How To Get Total Line Count From All Text Files In A Directory

From Dev

How to remove the last line of all files from a directory?

From Dev

How To Get Total Line Count From All Text Files In A Directory

From Dev

How to copy all files in directory recursively and unzip compressed files on fly

From Dev

How can I find, recursively, all files in my directory tree that first character in first line of each file is a space, a tab or a line break?

From Dev

How to recursively delete all .DS_STORE files from a directory on a Windows Machine?

From Dev

recursively copy all files from one directory to another with exceptions

From Dev

Search for a string in lots files in a directory, if found, save the file name and line

From Dev

How do I copy all files recursively to a flat directory in Ruby?

From Dev

How to use grep on all files non-recursively in a directory?

From Dev

How can I move all files in subdirectories recursively to a single directory?

From Dev

How to use grep on all files non-recursively in a directory?

From Dev

How can I move all files in subdirectories recursively to a single directory?

From Dev

How to recursively list all files of desired file type in a specified directory?

From Dev

How to find all files that contain the + sign on a directory recursively?

From Dev

How do I gunzip all files recursively in a target directory?

From Dev

How do I append a line to all .gitignore files recursively?

From Dev

How to prepend a line to all files in a directory?

From Dev

How to recursively delete directory from command line in windows?

From Dev

Recursively search directory of binary files for hexadecimal sequence?

From Dev

Recursively compress files in a directory and subdirectories using command line "zip" tool in Mac OS X and exclude .DS_Store files from ALL subfolders

From Dev

How to Search for Files Recursively into Subdirectories

From Dev

How to Search for Files Recursively into Subdirectories

From Dev

Search all xml files recursively in directory for a specific tag and grep the tag's value

From Dev

Recursively find all files that match a certain pattern

Related Related

  1. 1

    Command line to search all files in all text files in directory recursively

  2. 2

    How to search and remove ^M in all files in a directory recursively?

  3. 3

    Remove all but N files from directory recursively

  4. 4

    How to recursively search a directory for all files including hidden files in hidden directories, with PowerShell?

  5. 5

    How To Get Total Line Count From All Text Files In A Directory

  6. 6

    How to remove the last line of all files from a directory?

  7. 7

    How To Get Total Line Count From All Text Files In A Directory

  8. 8

    How to copy all files in directory recursively and unzip compressed files on fly

  9. 9

    How can I find, recursively, all files in my directory tree that first character in first line of each file is a space, a tab or a line break?

  10. 10

    How to recursively delete all .DS_STORE files from a directory on a Windows Machine?

  11. 11

    recursively copy all files from one directory to another with exceptions

  12. 12

    Search for a string in lots files in a directory, if found, save the file name and line

  13. 13

    How do I copy all files recursively to a flat directory in Ruby?

  14. 14

    How to use grep on all files non-recursively in a directory?

  15. 15

    How can I move all files in subdirectories recursively to a single directory?

  16. 16

    How to use grep on all files non-recursively in a directory?

  17. 17

    How can I move all files in subdirectories recursively to a single directory?

  18. 18

    How to recursively list all files of desired file type in a specified directory?

  19. 19

    How to find all files that contain the + sign on a directory recursively?

  20. 20

    How do I gunzip all files recursively in a target directory?

  21. 21

    How do I append a line to all .gitignore files recursively?

  22. 22

    How to prepend a line to all files in a directory?

  23. 23

    How to recursively delete directory from command line in windows?

  24. 24

    Recursively search directory of binary files for hexadecimal sequence?

  25. 25

    Recursively compress files in a directory and subdirectories using command line "zip" tool in Mac OS X and exclude .DS_Store files from ALL subfolders

  26. 26

    How to Search for Files Recursively into Subdirectories

  27. 27

    How to Search for Files Recursively into Subdirectories

  28. 28

    Search all xml files recursively in directory for a specific tag and grep the tag's value

  29. 29

    Recursively find all files that match a certain pattern

HotTag

Archive