How can I get the size of all files and all files in its subdirectories using the du command.
I am trying the following command to get the size of all files (and files in subdirectories)
find . -type f | du -a
But this prints out the folder sizes as well. How can I get a listing of sizes of all files and files in subdirectories? I also tried the exec flag
but I am not sure how to pipe the output into another command after it executes the results of find
into du
.
The operating system is AIX 6.1 with ksh shell.
find -print0
or other GNU features. If available, replacing\;
with\+
will result in fewer invocations ofdu
and thus better performance. – jw013 Oct 11 '11 at 22:02+
option. Is that an option fordu
or forfind
? And why does it result in less calls? – Amelio Vazquez-Reina Jul 19 '13 at 22:41find
. It specifies toexec
the command (in our casedu
) only once, with all the results offind
given as successive arguments to the command. – rahmu Jul 20 '13 at 02:25du -f --threshold=1G
– Alexander Mills Dec 22 '18 at 03:41+
option will not play well with some du flags (e.g.-c
) -- not in the original question, but a likely next step. This is because+
does not seem to be guaranteed to result in a single invocation of du: "the total number of invocations of the command will be much less than the number of matched". The # of invocations is probalby dependent on the max command size accepted by the current shell (?). So, behaviour may differ between systems. If you have GNU find/du @jw013's answer should be more reliable and adaptable to different needs that may arise. – m000 Aug 11 '23 at 03:46