A way to list directories that contain specific files.

Hi everyone

My issue is this, I need to list all the sub directories in a directory that contains files that have the extension *.log, *.dat and *.out . After reviewing the output i need to delete those directories i do not need. I am running Solaris 10 in a bash shell. I have a script that I believe will list the directories that I was hoping someone here could verify the syntax but I still need a way to delete them without having to do rm -R for each one.

find ABC/ \( -name "*.out" -o -name "*.log" -o -name "*.dat" \) -print | while read f
do
  echo "${f%/*}"
done | sort -u

ABC= name of directory

Thanks in advance

You can try:

 find . -type d -exec ls *.log *.dat *.out  \; | xargs -n 1 dirname | sort -u

Also it would be considerate if you posted this on a single site, rather than a bunch of sites.

This will expand *.log *.dat *.out in the directory in which find is run and will only produce the desired results if there are no files matching those three patterns in that directory.