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
.
alias
in your shell? Is your shell indeed bash (that's the default on most Linux systems, check the output ofps $$
)? Doesls --color=auto
output colors? – Gilles 'SO- stop being evil' Apr 25 '16 at 12:20alias lp='lp -o nobanner' alias lpr='lpr -h' alias md5sum='/usr/local/bin/md5' alias quota='/usr/local/bin/quota -v' alias tex2='export PATH=
– MatX Apr 25 '16 at 17:24echo $PATH | sed -e "s/\/opt\/teTeX3\//\/opt\/teTeX2\//g"
; export MANPATH=echo $MANPATH | sed -e "s/\/opt\/teTeX3\//\/opt\/teTeX2\//g"
' alias tex3='export PATH=echo $PATH | sed -e "s/\/opt\/teTeX2\//\/opt\/teTeX3\//g"
; export MANPATH=echo $MANPATH | sed -e "s/\/opt\/teTeX2\//\/opt\/teTeX3\//g"
'.bashrc
, or your shell isn't bash. What's the output ofps $$; cat ~/.bashrc
? – Gilles 'SO- stop being evil' Apr 25 '16 at 17:36ps $$; cat ~/.bashrc
is the following: PID TT S TIME COMMAND 14269 pts/18 S 0:00 -bash alias ls='ls --color=always' And yes, the ls --color=auto command also outputs colors, and yes, I restarted the shell session. Maybe I'm deprived of some rights by the admins? Is that possible? Or does it have to do anything with my default putty settings? – MatX Apr 25 '16 at 20:48