By default, ls
displays its output in multiple columns, but when it's sent to a pager such as less
it's reformatted as a single column. Is there any way I can page the original, multiple-column output and preserve the formatting?
By default, ls
displays its output in multiple columns, but when it's sent to a pager such as less
it's reformatted as a single column. Is there any way I can page the original, multiple-column output and preserve the formatting?
There are two options
the first shows the output in columns, where each column comes after the preceding (from the sorting point of view):
The second option puts the first elements on the first row, then on the second row and so on:
When piping to a pager, the terminal width and the color formatting are not taken into account from
ls
. To force this you can dowhere
-r
option toless
is needed to correctly interpret ANSI color sequences.Putting this line into a script do not work, because
COLUMNS
is not exported to subshells. Two work-around can be usedexport COLUMNS
in your~/.bashrc
implement that line as a function or an alias in
~/.bashrc