Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

How can I know if an alias I make (in .bash_aliases) is not replacing an actual command by same name? I don't want to do such things by accident.

(I looked in "Questions that may already have your answer" and "Similar Questions" but did not see matches)

I'm asking because I feel there is no warning given by the system (Ubuntu 13.10).

share|improve this question
add comment

3 Answers 3

up vote 5 down vote accepted

You can use type in terminal for this.

Say you have a command rm as alias rm -i. If you check,

type rm

you will get,

rm is aliased to `rm -i'

If you do not have any alias for rm you will get,

rm is /bin/rm
share|improve this answer
add comment

Before defining the alias for some command, call it fn, run type on the command name:

type fn

If there is no command of that name, type will return not found.

After you have defined an alias, you can use locate to check for possible conflicts:

locate '*bin/fn'

This looks anywhere on the system for a command named fn in a directory whose name would indicate that it is an executable. Note that this is not the same as type because locate will look in bin directories that may not be on your default path.

share|improve this answer
add comment

Warning: this method requires you to actually run the command, unlike the other answers that "report" on the shell state. You can never be sure till execution-time, can you?

In your shell, type

set -x

You will see + ... lines as the shell executes. For example, when I run ls, which is usually aliased to ls --color=auto on Ubuntu, I get this:

$ ls ~
+ ls --color=auto /home/rctay
bin         ext    foo.py      Music     shared     tmp-www                tmux-client-32280.log
...

To turn it off, run set +x.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.