commands ls and ls -C seem to produce the same results - display by columns.
Is there any difference?
commands ls and ls -C seem to produce the same results - display by columns.
Is there any difference?
Referring to info coreutils 'ls invocation':
-C'--format=vertical'List files in columns, sorted vertically. This is the default for ls if standard output is a terminal. It is always the default for the dir program. GNU ls uses variable width columns to display as many files as possible in the fewest lines.
TL;DR: no, no difference - that's default.
read the output of alias
your ls command is in probably doing ls -CF.
It may be set in your bash_rc file too.
so ls -F will also give the same output.
but you could change it, in which case, you might want it. OR you could use it in a script, and maybe you want that style of output.
ls > ls.txtandls -C > lsC.txt– R.M. Oct 31 '15 at 16:56ls > ls.txtandls -C > lsC.txtoutput just one column to a file . . . well , you're right ! The single column ( or-1flag ) is default output for file, which is what's happening withls > ls.txt. Withls -C > lsC.txtyou're missing something - the width ,-wor--width=COLSflag. When in terminal , width is automatically determined from the widths of your screen, but how does ls know width of a file ? It doesnt ! Try this:ls -C -w 300 > lsC2.txt– Sergiy Kolodyazhnyy Oct 31 '15 at 17:32ls -C > lsC.txtmakes multiple column output (for a ~80 character width, it looks like), whereasls > ls.txtis a single column. -- But my main point was that the '-C' option is not superfluous, and has a purpose when redirecting the output (i.e. when the output is not a terminal), and that "no, no difference" between with/without -C only applies to certain situations. – R.M. Oct 31 '15 at 20:01ls --version, by the way ? – Sergiy Kolodyazhnyy Oct 31 '15 at 20:28