What you should see is that in both cases you probably do not get the disk space usage of your pictures. If you have thousands of pictures, it probably on both cases exceeds the limit for the exec call.
Why? Well the -exec (...) +
command adds parameters to the execvp
system call. The man page defines the limit of its underlying system call as follow (extract from the execve man page):
Limits on size of arguments and environment
Most UNIX implementations impose some limit on the total size of the
command-line argument (argv) and environment (envp) strings that may be
passed to a new program. (...)
On kernel 2.6.23 and later, most architectures support a size limit
derived from the soft RLIMIT_STACK resource limit (see getrlimit(2))
that is in force at the time of the execve() call. (...) This change
allows programs to have a much larger argument and/or environment list.
For these architectures, the total size is limited to 1/4 of the
allowed stack size. (...) Since Linux 2.6.25, the kernel places a floor
of 32 pages on this size limit, so that, even when RLIMIT_STACK is set
very low, applications are guaranteed to have at least as much argument
and environment space as was provided by Linux 2.6.23 and earlier (This
guarantee was not provided in Linux 2.6.23 and 2.6.24.) Additionally,
the limit per string is 32 pages (the kernel constant MAX_ARG_STRLEN),
and the maximum number of strings is 0x7FFFFFFF.
So if you have a long list of files, you can quickly reach the system limits. In addition, when the relative path is longer, it is using more memory which can trigger that you reach limits faster, hence the different results of your 2 commands.
There is a solution
A solution on GNU systems is to use an input list of files to du
using the --files0-from
options. With your example:
find Selbstgemacht -type f -iname '*.jpg' -print0 | du --files0-from=- -ch
The first command lists all the files and outputs them on the standard output separated by NUL (\0
). This list is then "ingested" by du
from the standard input (the -
file name) and du
sum up the total.
-h
). Yes, I've added a note to that other question. – Stéphane Chazelas Aug 05 '14 at 09:37