Let's say I'm in the Desktop directory and want to count the number of files and directories whose name is exam
. It should also count the files containing the string exam
. So to sum it up I need to:
- Count the directories with the name
exam
- Count the files with the name and content
exam
Here is what I've tried so far.
ls -l | grep -r "exam" | wc -l
But this command counts only files with the content exam
.
What if I have a couple of directories: exam1
, exam2
, exam3
, and a couple of .txt files exam1.txt
, exam2.txt
, exam3.txt
, and want to count them?
exam
(for exampleexam1.txt
), or files whose content hasexam
in it?