I am hunting for a certain regular expression within the filenames and am seeking to return the parent folders with their sizes in a unique fashion.
For example, here is the command that I expected to work:
find -E . -type f -regex '.*[fF][oO][oO].*' -maxdepth 2 | rev | cut -d'/' -f2- | rev | egrep -v '\.$' | uniq | xargs du -sh
This failed with a:
xargs: unterminated quote thanks to varied quote marks within the filenames.
So I ended up utilizing
find -E . -type f -regex '.*[fF][oO][oO].*' -maxdepth 2 -print0 | rev | cut -d'/' -f2- | rev | egrep -v '\.$' | uniq | xargs -0 du -sh
Yet I ended up an error:
du: Binary file (standard input) matches thanks to
uniq apparently munging the output from find's
How would you suggest finding the parent folder size when searching for any file or folder under them that match? I repeat, I simply want to find the top level folder names with their accompanying sizes (
du -sh) and no subfolder path or file information so that I ultimately end up with just a nice neat list of main folders that have matching criteria.