I'm trying to move my bash configuration from Ubuntu to Mac OS X and it looks like ls is slightly different. For instance, it won't accept the --color
option.
How do I get this to work?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this communityls
is actually separate from Bash. Mac OS X has a BSD version of ls
, which requires -G
on the command line, or CLICOLOR
(and perhaps LSCOLORS
) in the environment.
See man ls
for more info.
CLICOLOR=Y
stopped working on my Mac. alias ls='ls -G'
would force ls
to colorize. I define this for interactive terminals only.
Oct 15, 2018 at 22:49
Use Homebrew.
brew install coreutils
Note that this will throw a prefix of g
in front of all the commands (e.g., gls
for ls
). It gives an option to source a file that will alias these for you automatically.
I wasn't sure if there was an option to install them directly without having to do the whole alias thing, so instead in installed MacPorts and did this.
compatibility for GNU and *BSD/darwin ls
~/.profile
#for *BSD/darwin
export CLICOLOR=1
ls --color=auto &> /dev/null && alias ls='ls --color=auto' ||
~/.bashrc (I don't remember if bash on Linux always reads ~/.profile, but not my zsh on ARCH)
[[ -f $HOME/.profile ]] && source $HOME/.profile
You'll need to install an alternate version of ls
. The one usually used in linux is from the GNU coreutils project.
You could build and install or install from macports, fink or homebrew.
ls
when the same feature is supported slightly differently on the existing version of ls
.
alias ls='ls -F'
Sep 2, 2010 at 17:37
gls
and doesn't replace the original so there's really no downside.
I use this Perl script I wrote on AIX. It’s useful if you’re on a system that doesn’t support --color
, and also where you don’t have sudo to install packages.
Should work on Macintosh too.
alias ls='ls --color'
alias ls='ls -G'
Combine 2 into 1, you can input this code into .bashrc (on both Linux & MacOS).
myos="$(uname)"
case $myos in
Linux) alias ls='ls --color-auto';;
Darwin) alias ls=ls -G';;
*);;
esac
Use homebrew install coreutils:
brew install coreutils
export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
useful link:https://github.com/sorin-ionescu/prezto/issues/966
ls --color=auto
.. eval $(dircolors)
set the LS_COLORS environment variable as expected but still no color without --color. ideas?
Feb 8, 2022 at 17:49
macOS now uses zsh
for the default terminal. To use ls
with color output edit or create the .zshrc
file in your home folder and add this:
export CLICOLOR=1
The other requirement is that ls
requires a color terminal declaration, such as xterm-16color
or xterm-256color
in your terminal application, or it won't bother trying to do color output.