How to execute a self-written command (such as ls) in any folder under linux

We need to add the directory where the executable file is located to the PATH environment variable.

  • 1
    sudo vim/etc/profile add a line: export PATH=$PATH:/script directory/
    remember to source and load the profile.
    There is a little problem with this: the colors on the command line are all gone

  • 2
    sudo vim /etc/environment, add the directory to the back of the PATH. I used this
    and remember to source and load the profile

Insert picture description here
*3
Put the executable file directly into /usr/bin or /usr/local/bin, because these files are already in the PATH

Guess you like

Origin blog.csdn.net/adlatereturn/article/details/104864130