The PATH environment variable for Linux

Source: Internet
Author: User

In Linux, we found that some commands can be executed in any directory, and there is no prompt to find the command file, which is where the path variable helps us locate it! First, let's take a look at the path variable

[Email protected]/]# echo $PATH/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

We can see that there are directories in the path variable, and separated by semicolons (:), the meaning of these directories is that when we execute a command, the system looks for the command in the directory of the path variable and executes it.

If a command exists in more than one directory, it will be executed first!

If we want to add a '/' directory to the PATH variable, you can use Path= "$PATH":/

[Email protected] etc]# path= "$PATH":/[[email protected] etc]# echo $PATH/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/ local/bin:/usr/sbin:/usr/bin:/root/bin:/

Now in order to verify the function of the path variable we can create a script file in the root directory to see if it can be used directly in other directories! Here is a simple creation of a script file 1.sh

#!/bin/bashecho "succeed!";

Now go to the/etc directory to see if it can run directly

[[email protected]/]# cd/etc/[[email protected] etc]# 1.sh succeed!

Can see the success! This means that when we manage a system, we can create a directory to add our own management scripts, add directories to the environment variables, so that we can use our own script files everywhere

The PATH environment variable for Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.