I am trying to install tomcat 8 on centos 7. I am using the terminal as root. When I type in source ~/.bashrc, the terminal gives back the following error: -bash: unalias: ls: not found.

How can I resolve this error so that the source ~/.bashrc command can succeed?

Note that I recently added the line unalias ls as the last line of ~/.bashrc as per @Cyrus' solution to this other problem related to color aliasing in the same CentOS installation.


I can't reproduce this but I assume the problem is because you have already unaliased ls once, so you can't unalias it again. However, I'm also pretty sure that the source command worked perfectly. Did you check? Chances are that it was sourced correctly and you can just ignore the error message.

More to the point, why are you running source ~/.bashrc? That file should be read when you start a new interactive non-login shell anyway. If it's to reload it because you made a change, then you're fine, your change was loaded. Ignore the error.


You should only attempt to unalias if it is actually an alias: Change

unalias ls


[[ $(type -t ls) == "alias" ]] && unalias ls

Consider putting unalias ls 2>/dev/null into your ~/.bashrc instead - that way it won't display the error message that you're seeing even if ls had already been un-aliased.

Consider, also, not logging into a root shell - if you don't understand what this error is telling you, I'd submit that logging into a root shell isn't a very good idea. With a regular user account, it's very difficult to make a mistake that breaks the system, and even more difficult to break it in a way that isn't fixed by rebooting. With a root shell, breaking a system is very easy.

  • 1
    I prefer glenn's approach to only unalias ls if its an alias instead of just hiding an error. – Michael Durrant Jun 27 '15 at 2:02
  • @MichaelDurrant, to play devil's advocate, maybe you shouldn't. They're functionally equivalent except that 1) the return values differ (0 for glenn's approach, 1 for mine), and 2) my approach is about 25x faster when timed in a tight loop. If 1) bothers you, just use unalias ls 2>/dev/null; true instead to fix up the return code. – godlygeek Jun 29 '15 at 16:17
[ -t 0 ] && unalias ls

This doesn't directly test whether ls is actually aliased, rather it tests for whether you are in a terminal, which is a little simpler especially if there is more code in your ~/.bashrc that you want treated the same:

if [ -t 0 ]; then
  unalias ls
  # ... any other terminal-only actions

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.