3 ms·
and your way breaks if a filename contains a new line.
by Hello71 10y ago
and your way breaks if a filename contains a new line.
- bdowling 10y agoYou can fix that by adding -B (or -b) to the ls command.
- mnaydin 10y agoNeither -b nor -B option is defined in the POSIX ls utility. The -b option is a GNU extension to print C-style escapes for nongraphic characters, and it is useful for this case. The -B option is also GNU extension not to list implied entries ending with ~, and I don't understand how it is relevant to this case.
- bdowling 10y agoOn OS X and BSD (at least, and possibly others) the -B option forces octal-style \xxx output for non-printable characters, while -b uses C-style escapes where possible. You are correct regarding the GNU option -B, which would not be relevant here, and regarding the fact that neither of these options are in POSIX. Thanks for pointing out those limitations.