Please consider accepting this patch I wrote which adds a new -0 feature
to ls.
This emits the entries separated by null bytes (similar to
/proc/$PID/cmdline) which creates a completely unambiguous and simple
output format that doesn't involve any quotation or escaping (like ls -1
and ls -Q1) by using a separator which cannot occur inside a filename
(\0). Inside emacs eshell for example, the output is nicely human
readable with the null separator displayed as ^@.
long_options, &oi);
if (c == -1)
break;
@@ -1949,6 +1950,10 @@
format = one_per_line;
break;
+ case '0':
+ format = null_separated;
+ break;
+
case AUTHOR_OPTION:
print_author = true;
break;
@@ -2763,7 +2768,8 @@
ls uses constant memory while processing the entries
of
this directory. Useful when there are many (millions)
of entries in a directory. */
- if (format == one_per_line && sort_type == sort_none
+ if ((format == one_per_line || format == null_separated)
+ && sort_type == sort_none
&& !print_block_size && !recursive)
{
/* We must call sort_files in spite of
@@ -3770,6 +3776,14 @@
}
break;
+ case null_separated:
+ for (i = 0; i < cwd_n_used; i++)
+ {
+ print_file_name_and_frills (sorted_file[i], 0);
+ putchar ('\0');
+ }
+ break;
+
case many_per_line:
if (! line_length)
print_with_separator (' ');
@@ -5150,7 +5164,8 @@
-x list entries by lines instead of by
columns\n\
-X sort alphabetically by entry extension\n\
-Z, --context print any security context of each file\n\
- -1 list one file per line. Avoid '\\n' with
-q or -b\
+ -1 list one file per line. Avoid '\\n' with
-q or -b\n\
+ -0 separate entries by a null byte.\n\
\n\
"), stdout);
fputs (HELP_OPTION_DESCRIPTION, stdout);