You have many questions. Lets try to answer them:
Is 'which' a built-in command?
Yes
- A builtin in some shells (csh, tcsh and zsh),
- A tracked alias (what the shell prints on
type which
for a hashed command (read about hash
)) in (lksh, mksh, ksh93, and attsh) and
- An external app in (dash, bash, yash).
So, there is not a general simple answer.
Can I override it?
Always, the order of execution is alias, special built-in, (and, after searching in the PATH) function, regular builtin, and external utility.
To override:
- an special builtin use an alias,
- a regular builtin (what which should be) use either an alias or a function.
- And, if the PATH is used, you can always add an executable ahead of others.
- Also, some shells may provide additional controls of builtins, like (%builtin) in path search of Minix I (1989) ash shell or enable/disable in ksh, bash, zsh
In openSUSE, Is the 'which' command a separate app?
Yes, as is also in Fedora, Debian and many others. But still, shells may have their particular say in this.
Is it a built-in command in other distros ?
That depends more on what shell you use than on what a distro decides to have as available files. A distro selects files, a shell selects builtins.
Will a 'which' command in the PATH override the default, built-in one?
No, as an app is the last executed element in the execution search sequence.
Does this also apply to the cd command and other built-in commands?
A cd
is an regular builtin, as such it could be override by an alias or a function (in Posix terms: only if an executable of the same name exists in the PATH).
which
is acsh
script from around 1980 that does not make sense with with Bourne Shell compatible shells, in special as it bases alias recognition on~/.cshrc
. – schily Jun 30 '20 at 13:40file /usr/bin/which
->executable /usr/bin/csh script
– schily Jul 02 '20 at 09:22