Ubuntu: Why won't ls display output in multiple columns, for some directories?



Question:

The ls command and the ntfs file systems have been discussed quite widely for the colours and how to tweak them using the dircolors option. However there seems more to it, which I have started to encounter only after my recent update from 14.04 to 16.04.

In the ntfs folders, I was able to turn of the color options, however the ls seems to spit out a single column of the files instead of a column view it has by default in other folders. Moreover, even forcing using the options -x, -c etc. give the same single column.

I don't have a problem with the colours as I can edit the dircolors options however I can't seem to change this single column view.

So I wish to ask if it is possible to eliminate these executable dependent issues including color and single column view that is dependent on the executable permissions (commonly seen in ntfs partitions) of the files and directories? I never had it till 14.04 and would like to restore that. I used to have directories color coded and that's okay.


Solution:1

As you may have found and as sudodus mentioned, --color=never prevents colorized output. However, it's not obvious if or how this is related to the number of columns being displayed.

You mentioned trying -c. That flag specifies a sort order and is unrealted to printing in multiple columns. The flag to print in columns is -C (i.e., a capital C). You may want to try this if you haven't, but I suspect it won't help in this particular situation.

Usually when you can't get ls to a directory's contents in multiple columns, it's because there's at least one file whose name is too long to fit while permitting a second, properly aligned column to be shown in your terminal.

Typically you simply won't want multiple columns displayed in that situation. The output wouldn't make much sense that way.

If that's what's happening, then you can list files in multiple columns by:

  • Increasing your terminal's width. If you're using a graphical terminal emulator, it's nearly always sufficient to just make the window bigger and run ls again. This usually works even over SSH.
  • Listing only some of the files. For example, perhaps you only really need to see files that end in .txt, and the files with really long names don't have that suffix. Then you could use ls *.txt.

If you've tried all this and are sure that's not what is going on and that the problem is caused by something you changed while configuring the colors used by ls, then more information will be needed. In particular, you'd have to specify what changes you made, show any files in which they were made -- or at least the relevant portions -- and provide the output of type -a ls.


Solution:2

From man ls

Using color to distinguish file types is disabled both by default  and with --color=never. With --color=auto, ls emits color codes  only when standard output is connected to a terminal. The LS_COLORS  environment variable can change the settings. Use the dircolors  command to set it.  

So an alias in ~/.bashrc should do it (after running source ~/.bashrc in already opened terminal windows and automatically in new terminal windows)

alias ls='ls --color=never'  

You can add the line near the other aliases.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »