Shell - How to find directory of some command?

前端 未结 7 946
既然无缘
既然无缘 2020-12-04 06:56

I know that when you are on shell, the only commands that can be used are the ones that can be found on some directory set on PATH. Even I don\'t know how to see what dirs a

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-04 07:21

    PATH is an environment variable, and can be displayed with the echo command:

    echo $PATH
    

    It's a list of paths separated by the colon character ':'

    The which command tells you which file gets executed when you run a command:

    which lshw
    

    sometimes what you get is a path to a symlink; if you want to trace that link to where the actual executable lives, you can use readlink and feed it the output of which:

    readlink -f $(which lshw)
    

    The -f parameter instructs readlink to keep following the symlink recursively.

    Here's an example from my machine:

    $ which firefox
    /usr/bin/firefox
    
    $ readlink -f $(which firefox)
    /usr/lib/firefox-3.6.3/firefox.sh
    

提交回复
热议问题