root@elastic-data:/mnt/elasticsearch/nodes/0/indices# du -sh * du: invalid option -- '6' du: invalid option -- 'w' du: invalid option -- 'U' du: invalid option -- 'g' du: invalid option -- 'E' du: invalid option -- 'Q' du: invalid option -- 'q' du: invalid option -- 'I' du: invalid option -- 'R' du: invalid option -- 'f' du: eQWyw: No such fileor directory du: invalid option -- 'F' du: xFiduSIGlLbpGulXyqA: No such fileor directory du: invalid option -- 'q' du: invalid option -- 'C' du: invalid option -- 'V' du: invalid option -- '4' du: invalid option -- 'o' du: invalid option -- 'R' du: invalid option -- 'G' du: invalid option -- '-' du: invalid -t argument 'tGc8A93BVw'
find
1 2 3 4 5 6 7 8
-print
True; print the full file name onthestandardoutput, followedbyanewline. If you are piping the output of find into another program and there is the faintest possibility that thefiles which you are searching for might contain a newline, then you should seriously consider usingthe -print0 option instead of -print. See the UNUSUAL FILENAMES section for information about how unusual charactersin filenames are handled.
1 2 3 4 5 6 7
-print0
True; print the full filenameonthe standard output, followed by a null charac‐ ter (instead ofthe newline characterthat -print uses). This allows file names thatcontain newlines or other types of white spaceto be correctly interpreted by programs that process the find output. This option corresponds tothe-0 option of xargs.
xargs
Deal with the problem of Argument list too long
1 2 3 4 5 6 7 8 9
xargs - build and execute command linesfrom standard input
-0
Input items areterminatedby a nullcharacter instead ofbywhitespace, and the quotes and backslash arenot special (every characteris taken literally). Dis‐ ables the endoffilestring, which is treated likeany other argument. Useful wheninput items might contain white space, quote marks, or backslashes. The GNU find -print0 option produces input suitable for this mode.
Examples
So for the above errors, using following command check size for the directores:
1
find ./ -type d -print0 | xargs -0 du -s | sort -nk1
➜ ~ find . -name "*.test" -print | xargs rm rm: cannot remove ‘./fi1e’: No such file or directory rm: cannot remove ‘3.test’: No such file or directory rm: cannot remove ‘./file’: No such file or directory rm: cannot remove ‘4.test’: No such file or directory