Re:A Terminal Case of Linux
by i15e on Tuesday May 30, 2023 @01:07PM
(#36127447)
Your original command should work fine.
find does not pass arguments through an intermediate shell, so there are no quoting concerns with regard to spaces in filenames, etc.
And with the form of -exec terminated by a ; it runs a single command for each matching filesystem entry, so there will be no issues with exceeding the maximum argument size.
You can verify via strace:
$ touch 'a b.md' 'c d.md'
$ strace -fe execve find . -iname '*.md' -exec unbuffer ls {} \;
At the end of the exec chains you should see the following:
find does not pass arguments through an intermediate shell, so there are no quoting concerns with regard to spaces in filenames, etc.
And with the form of -exec terminated by a ; it runs a single command for each matching filesystem entry, so there will be no issues with exceeding the maximum argument size.
You can verify via strace:
At the end of the exec chains you should see the following: The filenames are being passed through spaces and all.However if this were a real scenario, a better solution might be:
(Look up the -1 flag for ls, and the + variant of -exec for find for details)