-1

I want to recursively search for all files and sub-directories within a directory with sub string within file name as 'string.txt'

My command:

   cd /home/abcd/dir
   grep -R "*rate-trace.txt" | wc -l
TjS
  • 277
  • 2
  • 5
  • 16
  • 1
    https://unix.stackexchange.com/questions/248761/find-files-containing-string-in-file-name-and-different-string-within-file – RedX Dec 03 '18 at 11:46
  • 2
    Possible duplicate of [How can I recursively find all files in current and subfolders based on wildcard matching?](https://stackoverflow.com/q/5905054/608639), [Linux find file names with given string](https://stackoverflow.com/q/13131048/608639), [Find all files with name containing string](https://stackoverflow.com/q/11328988/608639), [How do I find all files containing specific text on Linux?](https://stackoverflow.com/q/16956810/608639), etc. – jww Dec 03 '18 at 12:21
  • @Inian, this is not realy the correct duplicate. This one is better: https://stackoverflow.com/questions/5905054/how-can-i-recursively-find-all-files-in-current-and-subfolders-based-on-wildcard – kvantour Dec 03 '18 at 12:35

1 Answers1

5

grep is searching the file's content.

Use find command instead:

find /home/abcd/dir -type f -name "*rate-trace.txt" | wc -l

OR

cd /home/abcd/dir
find . -type f -name "*rate-trace.txt" | wc -l
Jay jargot
  • 2,745
  • 1
  • 11
  • 14