Skip to main content

POSIX me harder

POSIX specifies that `-exec` can be ended by a semicolon or a plus sign, the latter taking the arguments as sets (up to ARG_MAX). That said, I wonder why many half-current implementations (RHEL 4; MacOS 10.4) of find(1) still don't understand the plus sign. When working with a lot of files the difference in speed is quite visible:

 $ find /dir -type f | wc -l
 3379
 
 $ /usr/bin/time -v find /dir -type f -exec ls {} + > /dev/null
 [...]
 User time (seconds): 0.05
 System time (seconds): 0.02
 Percent of CPU this job got: 98%
 Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.07
 Minor (reclaiming a frame) page faults: 781
 Voluntary context switches: 3
 Involuntary context switches: 11

 $ /usr/bin/time -v find /dir -type f -exec ls '{}' \; > /dev/null
 [...]
 User time (seconds): 1.69
 System time (seconds): 2.76
 Percent of CPU this job got: 49%
 Elapsed (wall clock) time (h:mm:ss or m:ss): 0:09.01
 Minor (reclaiming a frame) page faults: 938927
 Voluntary context switches: 3561
 Involuntary context switches: 4779