How would you write a script to find all the files with a specific extension in a directory and its subdirectories?

1 Answers
Answered by suresh

Shell Scripting: How to Find Files with Specific Extension

Shell Scripting: Finding Files with Specific Extension

One way to find all files with a specific extension in a directory and its subdirectories is by using the following shell script:

#!/bin/bash
# Script to find all files with specific extension in a directory and its subdirectories

echo "Enter the directory path:"
read directory

echo "Enter the specific file extension (e.g. .txt, .jpg):"
read extension

find "$directory" -type f -name "*$extension" 

Save this script in a file, give it executable permissions, and run it in your terminal to find all files with the specified extension in the directory and its subdirectories.

Answer for Question: How would you write a script to find all the files with a specific extension in a directory and its subdirectories?