Find the path of a Linux command

linux
Author

Youfeng Zhou

Published

November 15, 2022

Suppose we want to find the path of the command spark-submit in terminal, we have 4 ways to do it.

1. which command

!which spark-submit
/Users/youfeng/mambaforge/bin/spark-submit

With a parameter -a will print all matching paths. In this case, there is only one.

!which -a spark-submit
/Users/youfeng/mambaforge/bin/spark-submit

2. command command

!command -v spark-submit
/Users/youfeng/mambaforge/bin/spark-submit
!command -V spark-submit
spark-submit is /Users/youfeng/mambaforge/bin/spark-submit
Warning

We must pass the parameter -v or -V, otherwise, it will run the command.

3. type command

Show the path

!type -p spark-submit
spark-submit is /Users/youfeng/mambaforge/bin/spark-submit

Show the definition

!type spark-submit
spark-submit is /Users/youfeng/mambaforge/bin/spark-submit

Show the definition, excutable type, and path

!type -a spark-submit
spark-submit is /Users/youfeng/mambaforge/bin/spark-submit

4. whereis command

Show all the locations of the binary, source, manual page

!whereis spark-submit
spark-submit: /Users/youfeng/mambaforge/bin/spark-submit

Show the locations of the binary

!whereis -b spark-submit
spark-submit: /Users/youfeng/mambaforge/bin/spark-submit

Show the locations of the source