I am trying to do a find for folders begining with "of" and get their folder sizes

338 views Asked by At

Strangely this command works perfectly on 2 SLES11 servers, but not another. Here is my command ...

du `find -maxdepth 7 -type d -name of\*` -hs

and I get a result like ...

du: invalid option -- 'I'
du: invalid option -- 'n'
du: invalid option -- 't'
du: invalid option -- 'e'
du: invalid option -- 'r'
du: invalid option -- 'v'
du: invalid option -- 'i'
du: invalid option -- 'e'
du: invalid option -- 'w'
du: invalid option -- '/'
du: invalid option -- 'o'
du: invalid option -- 'f'
du: invalid option -- 'd'
du: invalid option -- 'j'
du: invalid option -- 'r'
du: invalid option -- 'I'
du: invalid option -- 'n'

And this is the result from an identically built server ...

du `find -maxdepth 7 -type d -name of\*` -hs
200K    ./xxxxxxxxx/xxxxxxx/xxxxxxx/of19darc
6.4G    ./xxxxxxxxx/xxxxxxx/xxxxxxx/ofkuoarc
188K    ./xxxxxxxxx/xxxxxxx/xxxxxxx/ofkuoarc/ofkuoarc
180K    ./xxxxxxxxx/xxxxxxx/xxxxxxx//data/Archive/ofw68arc
du: cannot access `yyy/Cyyyyy/GW': No such file or directory
du: cannot access `Archive/of19darc': No such file or directory

etc
2

There are 2 answers

2
Reinstate Monica Please On BEST ANSWER
du `find -maxdepth 7 -type d -name of\*` -hs

Will fail on any files that contain whitespace and will attempt to treat files starting with - (or having - after whitespace) as options to du.

Try something like

find -maxdepth 7 -type d -name of\* -exec du -hs -- {} \;

or if your find supports it (the faster)

find -maxdepth 7 -type d -name of\* -exec du -hs -- {} +
0
Prabhu R.D On

Use This:

du -h $(find . -type d -name 'of*')