How to find application's path from command line?

  • For example, I have git installed on my system. But I don't remember where I installed it, so which command is fit to find this out?

    Heh, heh "`which` command" indeed :)

  • Arcege

    Arcege Correct answer

    9 years ago

    If it is in your path, then you can run either type git or which git. The which command has had problems getting the proper path (confusion between environment and dot files). For type, you can get just the path with the -p argument.

    If it is not in your path, then it's best to look for it with locate -b git It will find anything named 'git'. It'll be a long list, so might be good to qualify it with locate -b git | fgrep -w bin.

    I use `locate` endlessly (it is very fast), but for those unaware of it, `locate` is only as up to date as its most recent database update, which is automatically run daily on my Ubuntu. The *refresh* command is `sudo updatedb` ... Also `locate` has built-in regex capability, so commands like this works: `locate -br "^git$"` ... -b` means restrict the search to just the *basename* ... or without the `-b`, it searches the full pathname .. Also, it only searches paths you have configured it to search.. there is no command-line control of this other than your regex filters.

    @Gilles, that's funny for me the behavior is exactly the opposite: `type` is a shell builtin that tells me aliases and such, and `which` is an external program that shows me the path to an executable... although if there's a builtin that gets in the way that executable won't get called.

    @quodlibetor The problems with `which` are that it doesn't know about shell built-ins and functions (which is relevant when you're wondering what typing the command will do), and it uses a different `$PATH` on some systems.

License under CC-BY-SA with attribution


Content dated before 6/26/2020 9:53 AM