Skip to content
Advertisement

Why `which pushd` doesn’t return anything? [closed]

My understanding is that all commands in linux must exist on the $PATH, even for the most basic commands

> which cd
/bin/cd
> which ls
/bin/ls

But when I tried which pushd, to my surprise, it returned:

/usr/bin/which: no pushd in (/bin:/usr/share/maven/bin:/usr/share/java/jdk1.8.0_131/bin:/usr/local/bin:/usr/bin:/usr/local/sbin)

pushd is “installed” and working. This challenges my whole understanding of linux commands.

Can someone explain why this is happening?

Advertisement

Answer

Can someone explain why this is happening?

pushd, like many other commands, is a builtin. which is itself an executable and which searches for executables – there is no such executable as pushd.

To affect the current working directory of the shell itself, it has to be a builtin, just like cd.

You can check what it is with type:

$ type pushd
pushd is a shell builtin

what are other examples of such shell builtins?

They are listed in documentation: https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Shell-Builtin-Commands .

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement