I want to find all directories containing, for example, files named *.txt. but the output must not contain duplicates. How to do it?
Bash – How to show distinct directories on find
bashfind
bashfind
I want to find all directories containing, for example, files named *.txt. but the output must not contain duplicates. How to do it?
Best Answer
Try:
This works as follows:
find . -type f -name "*.txt" -printf '%h\n'
- find all files that end in*.txt
and print it's directory (%h
) followed by a newline.| sort
- sort the directories| uniq
- remove duplicates