One of the things I love is being able to enter into a directory via terminal, list the contents, and quickly see which ones are executable or not and which ones are directories or are not directories IN COLOR (not everyone is perfect right?). This is specifically handy as I move through working with Slackware based distributions like the one I’m using now, Zenwalk Linux 6 and the /etc/rc.d/ directory. Most of the Red Hat based distributions out there that I’ve used have this set automatically…so I’m used to it. When I opened up a terminal in Zenwalk I found no color. A quick investigation of ~/.bashrc showed me that there are aliases set to display color…instead of ls I’d just use the letter L; 2 l’s for another option, 3 for another. It’s interesting, but not normally how I do business. See bashrc below:
<br /> devnet[~]$ cat ~/.bashrc<br /> alias lll="ls -al --color"<br /> alias ll="ls -l --color"<br /> alias l='ls --color'<br />alias search='find . -name'<br /> alias aterm="aterm -fg white -tr"<br /> alias version='cat /etc/zenwalk-version'<br /> alias dh='df -h'<br />export PS1='\u[\W]\$ '<br /> export PAGER="most"<br />devnet[~]$<br />
I don’t use those aliases much…others of you might do the ‘ll’ or ‘lll’ but it’s just not part of my routine. So, I added in just after line 4 in the code above:
<br /> alias ls='ls --color'<br />
You can do this a few different ways…with any command line editor like emacs, vi, or nano/pico. It’s really up to you. The easiest way for new users is to use a text editor:
<br /> devnet[~]$ mousepad ~/.bashrc<br />
This will launch the mousepad text editor in XFCE. If you’re in Gnome, try gedit. If KDE, give kwrite a try. You should see something like the following window pop up for editing:
You should see in the picture above, I’ve added in the alias needed to make me comfortable. After that, File >> Save. You’re set! Except, you may notice that when you type the command ‘ls’ there are no colors. So what gives? Well, we haven’t loaded our ./bashrc since we changed it. You don’t have to logout and back in to get things to work though…you can do this right from the terminal:
<br /> devnet[~]$ exec bash<br />
Now try giving the ‘ls’ command a try again and you should see that it is in color. I know a lot of the more advanced Linux guys out there are probably saying, “why’d he waste a post on this! It’s easy” and you’d be right for a majority of users out there…I hope that this post finds some new user out there that may be stuck for an answer on how to do this. One final note on this as well: You will have to do this as the root user and change /root/.bashrc in order for your root user to also have color. Thanks for reading!
This content is published under the Attribution-Noncommercial-Share Alike 3.0 Unported license.