which command tutorial in linux/unix with examples and use cases

linux which command – locate a command in the user’s path.

Which command does this by searching the PATH for executable files matching the names of the arguments. It returns the pathnames of the files (or links) which would be executed in the current environment.

Syntax

       which [-a] filename ...

Options

  • -a
    print all matching pathnames of each argument

Examples

Locate a command

➜  ~ which env
/usr/bin/env

Print all matching pathnames of each argument

➜  ~ which -a env
/usr/bin/env
/bin/env

Add a Comment

Your email address will not be published. Required fields are marked *