How do I list the files having particular strings from group of directories in bash?

sree

I want to list files having EXACT strings like "hello", "how" and "todo" from a directory (which is having multiple directories). Also I want to list c(.c) and cpp (.cpp) files only. I have tried with grep -R (grep -R "hello" /home) but not satisfied. Please help me to enhance my grep -R command or any alternate way. Thanks in advance.

umläute

if you want to find files, a good start is usually to use find.

if you want to find all .cpp and .-c files that contain the strings "hello", "how" or "todo" in their content, use something like:

find /home \( -name "*.c" -or -name "*.cpp" \) \
    -exec egrep -l "(hello|how|todo)" \{\} \;

if instead you want to find all .cpp and .-c files that contain the strings "hello", "how" or "todo" in their filenames, use something like:

find /home                                                       \
   \( \( -name "*.c" -or -name "*.cpp" \)                        \
      -and                                                       \
      \( -name "*hello*" -or -name "*how*" -or -name "*todo*" \) \
   \)

there is a bit of quoting (using \) involved, as (), {} and ; are considered special characters by the shell...

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Copying files from directories having spaces in its name

分類Dev

How do I only list specific files with 'ls' in bash?

分類Dev

How to get particular record from a group in R

分類Dev

How do I stop a scheduled local notification from triggering after a particular date?

分類Dev

How do I correctly use try_files when looking in two different directories for files to serve?

分類Dev

How do i eliminate the duplicate count from mysql Group by result?

分類Dev

How do I rename several files in folders following the order of a list

分類Dev

In racket how do i combine strings in a list to create one sentence

分類Dev

How do I find vertices without particular edges from a particular vertex in Gremlin?

分類Dev

How do I restrict the user input to particular strings, which are already stored as a variable(s)?

分類Dev

How do I subtract these 2 list in Bash

分類Dev

how to open multiple file from single file which is having list of files in python and how to do processing on them?

分類Dev

How to view list of backup files on a particular date

分類Dev

Get a list of directories or files I don't have permission to read

分類Dev

How do I find all files that are *not* group writeable?

分類Dev

How do I list word count in multiple files?

分類Dev

How do I list all installed packages from the command line in bash / osX

分類Dev

How do I make files downloadable for a particular role in Plone?

分類Dev

How can I count files with a particular extension, and the directories they are in?

分類Dev

How to list files from n biggest directories?

分類Dev

How to find / list all unique files across two directories?

分類Dev

How to find the first occurrence of any string given a particular group of strings?

分類Dev

How do I import data from Activie directories through LDAP URL

分類Dev

How to list packages with files in a particular directory?

分類Dev

ls --group-directories-last ? (List directories AFTER files)

分類Dev

How do I print a list of strings into a table in python?

分類Dev

How do you list the folder permissions of only certain directories that follow a common pattern in a particular directory?

分類Dev

merging particular text files in different directories

分類Dev

list only direct child directories of all directories with a particular name

Related 関連記事

  1. 1

    Copying files from directories having spaces in its name

  2. 2

    How do I only list specific files with 'ls' in bash?

  3. 3

    How to get particular record from a group in R

  4. 4

    How do I stop a scheduled local notification from triggering after a particular date?

  5. 5

    How do I correctly use try_files when looking in two different directories for files to serve?

  6. 6

    How do i eliminate the duplicate count from mysql Group by result?

  7. 7

    How do I rename several files in folders following the order of a list

  8. 8

    In racket how do i combine strings in a list to create one sentence

  9. 9

    How do I find vertices without particular edges from a particular vertex in Gremlin?

  10. 10

    How do I restrict the user input to particular strings, which are already stored as a variable(s)?

  11. 11

    How do I subtract these 2 list in Bash

  12. 12

    how to open multiple file from single file which is having list of files in python and how to do processing on them?

  13. 13

    How to view list of backup files on a particular date

  14. 14

    Get a list of directories or files I don't have permission to read

  15. 15

    How do I find all files that are *not* group writeable?

  16. 16

    How do I list word count in multiple files?

  17. 17

    How do I list all installed packages from the command line in bash / osX

  18. 18

    How do I make files downloadable for a particular role in Plone?

  19. 19

    How can I count files with a particular extension, and the directories they are in?

  20. 20

    How to list files from n biggest directories?

  21. 21

    How to find / list all unique files across two directories?

  22. 22

    How to find the first occurrence of any string given a particular group of strings?

  23. 23

    How do I import data from Activie directories through LDAP URL

  24. 24

    How to list packages with files in a particular directory?

  25. 25

    ls --group-directories-last ? (List directories AFTER files)

  26. 26

    How do I print a list of strings into a table in python?

  27. 27

    How do you list the folder permissions of only certain directories that follow a common pattern in a particular directory?

  28. 28

    merging particular text files in different directories

  29. 29

    list only direct child directories of all directories with a particular name

ホットタグ

アーカイブ