Once the output of ls
is on the terminal, it stays colored. But if you run ls
again, whether the output is colored depends on the options you pass to ls
this time. The ls
command doesn't remember settings from one time to the next.
If you want to have default settings for a command, define an alias for it. For bash, the file where aliases are defined is .bashrc
. So add the following line to your .bashrc
:
alias ls='ls --color=auto'
In addition, bash doesn't read .bashrc
if it's a login shell, only if it's an interactive non-login shell. To get the same interactive configuration in both cases, put the following line in your .bash_profile
:
if [ -e ~/.profile ]; then . ~/.profile; fi
case $- in *i*) . ~/.bashrc;; esac # Load .bashrc if this login shell is interactive
For future customizations, use .profile
or .bash_profile
for session startup things like environment variables and .bashrc
for interactive customizations such as aliases and shopt
settings
If you ever want to run the ls
program and bypass your alias, run \ls
instead of ls
.