I need to find every folder with more than one PDF in a folder structure but hide the pesky hidden files such as .HResource
files that infiltrate our file system.
I only want to filter folders that have HiRes in the filename.
Ideally I want to run this at top level so it searches every folder with HiRes and spits out the folders with more than one PDF inside it.
The OS is RHEL 7 and this command can be run as user/root as required.
I have had a play with
find -type f -iname '*.pdf' -iname '*HiRes*' ! -iname '.*' -printf '%h\n' | sort | uniq -d
but have had very little luck so far as the hidden files keep showing and thus in a 11,000 folder system giving thousands of false positives. For example, given the following directory structure,
.
|--Apples.HiRes1
| |--Gala.pdf
| |--Granny Smith.pdf
| |--McIntosh.pdf
| |--Red Delicious.pdf
|--Banana-HiRes2
| |--upper.pdf
| |--subdir
| | |--lower.pdf
|--Cherry_HiRes3
| |--Bing.pdf
| |--Blossom.jpg
| |--.pesky
| |--.hidden
| |--.files
| |--.HResource
|--Dates (HiRes4)
| |--Midsummer.Pdf
| |--New Year’s Eve.PDF
|--Employees
| |--Fred.pdf
| |--Ginger.pdf
| |--New Hires
| | |--Sam Malone.pdf
| | |--Woody Boyd.pdf
|--Gemstones
| |--Rubies
| | |--1.pdf
| | |--2.pdf
| |--Sapphires
| | |--3.pdf
| | |--4.pdf
|--Tomato.HiRes
| |--Bacon
| |--Lettuce
| | |--5.pdf
| | |--6.pdf
|--Zucchini.LoRes
| |--Bread.pdf
| |--Squash.pdf
the output should be
./Apples.HiRes1
./Dates (HiRes4)
Note that
Cherry_HiRes3
is excluded because it has only one PDF file in it.Banana-HiRes2
andTomato.HiRes
are excluded because they have two PDF files under them, but not in them.Zucchini.LoRes
is excluded (obviously) because its name hasLoRes
rather thanHiRes
.
find
command by itself, and looking at the output? Is it what you expect? Does that help you? (2) Another debugging technique is to explain your problem to a rubber duck. Can you explain how you believe your solution should work, and what output you expect to get from thefind
command? (3) Do you have files with names like.MRducks.pdf
? If not, I don’t understand what issue you could possibly be having with “pesky hidden files” such as.HResource
. Can you explain? … (Cont’d)*HiRes*
test to be case-insensitive? Note that, if you do, “New hires” and “Sapphires” will be listed.