Alias does not "override" PATH entries?

The which command returns only executables: it knows nothing about aliases, since it is an external program, and there is no mechanism for passing alias information to a child process.

If you enter the command type -a cp you will see all possible interpretations, in order of preference. This includes any alias, since type is a bash internal command.

It is important to realise that an alias will not be interpreted by a sub-process, such as a script or an interactive editor which has an option to run system commands.

If you make cp a function, then your version will run in scripts, though not from other programs:

cp() { /usr/local/bin/gcp "$@"; }

If you want your cp to work everywhere, add $HOME/bin at the head of your PATH list and point $HOME/bin/cp to point to it:

ln -s /usr/local/bin/gcp $HOME/bin/cp

This makes a symbolic link, though you can make it a slightly more efficient hard link (omit -s), but this will normally need root permissions (sudo ln ...). Creating a function and adding to the PATH variable will be done in one of the bash start-up scripts, with user permissions.


Aliases are internal to the shell. Other programs won't know about them.

which is not a Bash builtin (it is a builtin in some other shells, e.g. zsh). Since which has no privileged information into Bash's aliases, which just looks through PATH for the given term.

type, on the other hand is a Bash builtin, so it can report on aliases.