user3269839
user3269839

Reputation: 15

bash script to check for folders containing two specific files recursively and print their path

I want to check recursively for two specific files say "hem" and "haw" and print the folders containing both the files.

Upvotes: 0

Views: 41

Answers (2)

pjh
pjh

Reputation: 8064

Try this Shellcheck-clean code:

shopt -s globstar

for hempath in ./**/hem ; do
    dir=${hempath%/*}
    [[ -e $dir/haw ]] && printf '%s\n' "$dir"
done

Upvotes: 0

bobah
bobah

Reputation: 18864

find <top_folder> -name hem -o name haw -print

or

cd  <top_folder>
ls **/hem **/haw

Upvotes: 1

Related Questions