Ubuntu: search in subdirectories for all html files containing the tag


I have a directory include many files of different extensions. What I want is to list all .html files only that contains the tag .


From the terminal, use the find command to find all the files ending in .html and use the grep command to filter the results to show only the names of files that contain the <abbr> string:

cd /path-to-dir ## change directories to the root directory that you are searching from  find . -name "*.html" -exec grep -l '<abbr>' {} +    

The find command searches for files in a directory hierarchy recursively by default.

Or combine the two commands into a single command:

find /path-to-dir -name "*.html" -exec grep -l '<abbr>' {} +  


A simple solution:

grep -r "<abbr" --include="*.html" /path-to-dir  
  • use -r for all subdirectories.
  • Use --include='*html' to match html files only.


For verification (namely, the file name and the lines with <abbr>), you may use a simple:

grep '<abbr>' /path-to-dir/*.html  

If you want file names only, use the following:

grep '<abbr>' /path-to-dir/*.html | awk -F: '{ print $1 }' | sort | uniq  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »