1

I'm using Windows Terminal to SSH into an Ubuntu virtual machine. When I issue the ls command, the output is a single column, similar to ls -al but without the extra info. I want the output displayed in the usual default format, where directories and files are displayed horizontally in the terminal.

I looked in my ~/.bashrc file, but I don't see anything that would cause this default behaviour.

Do you happen to know why this could be happening? The last time I logged in (a couple of months ago), it was working as expected.

2
  • 2
    Do you have one or several exceptionally long filenames in the directory that you are testing this in? Is it the same everywhere? What is the exact command you are using and are you typing it on the command line or running it via a script? Does ls -C produce output in columns? What does type -a ls say? Are you running ls as root or as some other user?
    – Kusalananda
    Commented Jan 30, 2023 at 19:50
  • I think you nailed it. In the few directories I was doing this in, there was 1 really long file. I suppose ls will print in a column if it can't wrap that 1 file
    – u84six
    Commented Feb 1, 2023 at 18:16

1 Answer 1

4

In the comments to the question, you say you have a very long name in the affected directory. The ls utility will adjust the width of the columns to accommodate the longest filename. If one filename is really long, this may have the effect that ls chooses to display everything in a single column, depending on the width of the terminal window (or the value of the COLUMNS environment variable).

Examples

Short filenames:

$ touch {1..20}
$ ls
1       11      13      15      17      19      20      4       6       8
10      12      14      16      18      2       3       5       7       9

Adding a long name will expand all columns to accommodate names of that length:

$ touch longerfilename
$ ls
1               14              19              5               longerfilename
10              15              2               6
11              16              20              7
12              17              3               8
13              18              4               9

If a filename is too long for even two columns, ls shows the output in a single column. The utility will always output columns of the same width.

$ touch really-really-really-long-name-of-a-file
$ ls
1
10
11
12
13
14
15
16
17
18
19
2
20
3
4
5
6
7
8
9
longerfilename
really-really-really-long-name-of-a-file

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .