Linux PATH environment variable and path Environment Variable
In linux, we find that some commands can be executed in any directory, and there is no prompt that the command file cannot be found. This is what PATH variable helps us locate it! First, let's check the PATH variable.
[Root @ localhost/] # echo $ PATH/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin: /usr/bin:/root/bin
We can see that some directories are stored in the PATH variable and separated by semicolons (:). The meaning of these directories is that when we execute a command, the system will find and execute this command in the directory of the PATH variable,
If a command exists in multiple directories, It will be executed first!
If you want to add a '/' directory to the PATH variable, you can use PATH = "$ PATH ":/
[Root @ localhost etc] # PATH = "$ PATH":/[root @ localhost etc] # echo $ PATH/usr/lib64/qt-3.3/bin: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin :/
Now, to verify the role of the PATH variable, we can create a script file in the root directory to see if it can be directly used in other directories! A script file 1.sh is created.
#! /Bin/bashecho "succeed! ";
Now go to the/etc directory to see if it can run directly
[Root @ localhost/] # cd/etc/[root @ localhost etc] # 1.sh succeed!
You can see that the operation is successful! That is to say, when we manage a system, we can create a directory to add scripts for management, and add directories to environment variables, so that we can use our own script files anywhere.
It's really convenient!