Consider the following:
$ echo index.html* | xargs -L 1 ls -l -rw-r--r-- 1 zeki zeki 17198 2011-05-03 23:18 index.html -rw-r--r-- 1 zeki zeki 17198 2011-05-03 23:20 index.html.1 -rw-r--r-- 1 zeki zeki 17198 2011-05-03 23:21 index.html.2 -rw-r--r-- 1 zeki zeki 146589 2011-05-05 12:29 index.html.3 $ echo index.html* | xargs -n 1 ls -l -rw-r--r-- 1 zeki zeki 17198 2011-05-03 23:18 index.html -rw-r--r-- 1 zeki zeki 17198 2011-05-03 23:20 index.html.1 -rw-r--r-- 1 zeki zeki 17198 2011-05-03 23:21 index.html.2 -rw-r--r-- 1 zeki zeki 146589 2011-05-05 12:29 index.html.3
Why does the -n option yield an incorrect formatting? Just in case, I’m using bash under Ubuntu. Thanks.
Advertisement
Answer
-L
splits by lines; echo
doesn’t separate its output by lines but by spaces, so a single ls -l
is run and that formats all the columns as a group.
-n
splits by parameters; in the absence of -L
or -0
, the separator is whitespace (possibly modified by quoting), so each filename gets its own ls -l
run and there is no way for the independent runs to coordinate column widths.