MacOS – Is it possible to fix the spacing when using “ls” with colored output

bashcommand linemacosterminal

This is the exact same issue found here:
https://unix.stackexchange.com/questions/165154/changing-the-spacing-between-files-in-ls

When you run the command ls -G or CLICOLOR=1; ls the spacing in the output gets squished.

These images demonstrate what's going on (taken from the old thread):

Running ls when CLICOLOR is unset or set to 0:
<code>ls</code> when <code>CLICOLOR</code> is unset or set to 0

Running ls -G:
<code>ls -G</code>

This happens in any terminal emulator (terminal.app, iterm, kitty) and any shell (bash, zsh).

As the commenter points out in the previous thread, this is caused by ls -G setting f_notabs=1. From the source file https://opensource.apple.com/source/file_cmds/file_cmds-242/ls/ls.c.auto.html:

    if (f_color) {
        /*
         * We can't put tabs and color sequences together:
         * column number will be incremented incorrectly
         * for "stty oxtabs" mode.
         */
        f_notabs = 1;
        ...

Is there any way to fix this? I can't find any information on this since 2014.

Obviously this isn't the end of the world, but ls is one of the most frequently called shell commands and being able to have both color and nice spacing makes things easier to read. I am surprised there seems to be very little written about this as I would expect it to impact a large number of people.

Best Answer

If your using Terminal or iTerm you can go to preferences and look for option to change fonts. For iTerm its shown in the image below.

enter image description here

If you click on the change font button you get the following pane.

enter image description here

As you can see in this image there are sliders to adjust the character spacing. you can spread the characters out on the iTerm windows.