1

I was wondering if any of you knew why doesn't my terminal keep displaying stuff colored, after I use the command ls -l -a --color=always I would like it to stay colored, so when the next time I type ls -l -a it is colored.

Just to make it clear, I'm using Windows 10, and then with putty I SSH into a server, where I have an account, and it runs Linux.

1

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.

  • Thank you for your advice. I did not find any .bashrc file in my user folder, so I created one, and inserted the line of code you suggested. Afterwards, it still remained monochrome instead of colorful. – MatX Apr 25 '16 at 10:04
  • @MatX What is the output of alias in your shell? Is your shell indeed bash (that's the default on most Linux systems, check the output of ps $$)? Does ls --color=auto output colors? – Gilles Apr 25 '16 at 12:20
  • This is the result of the alias command: alias 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=echo $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"' – MatX Apr 25 '16 at 17:24
  • @MatX The alias isn't present, so either you made a mistake when creating .bashrc, or your shell isn't bash. What's the output of ps $$; cat ~/.bashrc ? – Gilles Apr 25 '16 at 17:36
  • @MatX Oh, and did you start a new shell? The rc file is only read when the shell starts. – Gilles Apr 25 '16 at 17:37

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.