This is more of a cosmetic question but this is really bugging me. On OS X, when I run ls -G (or use CLICOLOR=1) instead of regular ls it changes the spacing of the columns, as you can see in this picture:

ls vs ls -G spacing

Is there a way to change the spacing so that running ls -G produces the same spacing seen in the regular ls?




NOTE: from the ls man page on OSX

-G      Enable colorized output.  This option is equivalent to defining 
        CLICOLOR in the environment.  (See below.)
  • Looking at the source in opensource.apple.com/source/file_cmds/file_cmds-242/ls it looks like enabling colors sets f_notabs, since it doesn't want to use hard tabs in combination with ANSI erscape sequences, but this also sets tabwidth to 1 (it would otherwise be 8), which increases the number of available columns. I don't see a way to change this short of altering the source code. – Mark Plotnick Oct 31 '14 at 16:21
  • @MarkPlotnick Have you found any solution in five years? The problem still exists. – Nanashi No Gombe Jul 19 at 13:07
  • @NanashiNoGombe A workaround might be to use Homebrew to install GNU coreutils, and use its GNU ls. See the answers to the question How to replace Mac OS X utilities with GNU core utilities – Mark Plotnick Jul 23 at 18:54

I'm not sure what version of OSX & the various tools you are using but I have the following setup on my OSX system and ls -G shows the same column alignments as the vanilla ls.



My setup consist of the following environment variables.

$ env|grep -Ei "cli|ls|col"
  • It is a fresh install of OS X Yosemite with no environment variables set save for PS1="\t:\w\$ ". In the screenshot, CLICOLOR is disabled. However, with CLICOLOR enabled, ls produces the same spacing that ls -G produces in the screenshot. – Alex W. Oct 31 '14 at 15:22
  • @AlexW. - so then what's the issue? If you set that variable all is right, no? – slm Oct 31 '14 at 15:24
  • No. When I said that CLICOLOR=1 produces the same spacing that ls -G produces with CLICOLOR=0, I mean that it is still changing the spacing of ls. You can see this clearly in the output of ls. With CLICOLOR disabled, the result is two rows of items whereas CLICOLOR=1 will produce only the one row. See the new screenshots I added for clarity. – Alex W. Oct 31 '14 at 15:36
  • @AlexW. - OK, thanks for the update in the Q. What terminal emulator are you using here? I've replicated my tests in iTerm, Terminal, and SSH'ed into the box from a Linux box. The ls -G output I show is consistent on all three. – slm Oct 31 '14 at 15:55
  • It's the OS X default terminal, using the "Pro" default profile. – Alex W. Oct 31 '14 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.