Fixing Unix/Linux/Posix Filenames

Fixing Unix/Linux/Posix Filenames

This article will discuss, in particular, the three biggest problems: control characters in filenames (including newline, tab, and escape), leading dashes in filenames, and the lack of a standard character encoding scheme (instead of using UTF-8). Problem is, the “obvious” for loop won’t work either, for the same reason; it breaks up filenames that contain spaces, newlines or tabs:

Now at this point, some of you may suggest using xargs, like this:

Yet this is wrong on many levels. POSIX has more recently extended find so that find -exec … {} + (plus-at-end) creates sets of filenames that are passed to other programs (similar to how xargs works); this is faster, but it still creates new processes, making tracking-while-processing very inconvenient.

Source: dwheeler.com