Linux PATH environment variable and path Environment Variable

Source: Internet
Author: User

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!

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.