简体   繁体   中英

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.

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

or

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

Try this Shellcheck -clean code:

shopt -s globstar

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM