Changes to the Linux environment variables (permanent, temporary) and the time format for modifying the LS display

Source: Internet
Author: User

This article transferred from: http://blog.sina.com.cn/s/blog_8e21864f01014u9h.html

Linux modifies environment variables, very simple but important

I. Variant types of Linux

According to the lifetime of the variables, the Linux variables can be divided into two categories:

1. Permanent: Need to modify the configuration file, the variable is permanent.

2. Temporary: Using the Export command-line declaration, the variable is invalidated when the shell is closed.

Ii. three ways to set up variables

1. Add the variable "to all users (permanent)" in the/etc/profile file

Using VI to add a variable to the file/etc/profile file, the variable will be valid for all users under Linux and is "permanent".

Example: Edit the/etc/profile file, add the CLASSPATH variable

# Vi/etc/profile

Export classpath=./java_home/lib; $JAVA _home/jre/lib

Note: If you want to run the file immediately after you modify it, you can only take effect the next time you re-enter the user. Source/etc/profile.

2. Add variable "to single user (permanent)" in. bash_profile file in User directory

Use VI to add variables to the. bash_profile file in the user directory, and change the amount to be valid only for the current user and be "permanent".

For example: Edit the. Bash_profile under the Guok User directory (/home/guok)

$ vi/home/guok/.bash.profile If you do not change the. bashrc file.

Add the following content:

Export classpath=./java_home/lib; $JAVA _home/jre/lib

Note: If you want to take effect immediately after modifying a file, run $ source/home/guok/.bash_profile or you can only take effect the next time you re-enter the user.

3. Run the export command directly to define the variable "valid only for the current shell (BASH)"

The variable is defined directly under the Shell's command line using the [export variable name = variable value], which is valid only under the current shell (bash) or its child shell (bash), the shell is closed, the variable is invalidated, and the new shell is opened without this variable. You need to redefine the words you need to use.
Third, another

1. Use the readonly command to set the read-only variable, and if the readonly command is used, the variable cannot be modified or erased.

2. Use the unset command to clear the environment variable $ unset temp_kevin #删除环境变量TEMP_KEVIN

1 Modify the time format of the LS display2 [SQL] View plaincopy3[Email protected] dataload]$ls-L4Total28896  5Drwxr-xr-x8Liul Liul4096Sep -  -:Tenpyyaml-3.10  6-rw-r--r--1Liul Liul241524Sep -  -: +pyyaml-3.10.Tar. GZ7-rwxr-xr-x1Liul Liul14466821Feb -   -greenplum-loaders-4.2.1.0-build-2-rhel5-X86_64.bin8-rw-r--r--1Liul Liul14304561Mar1   -greenplum-loaders-4.2.1.0-build-2-rhel5-x86_64.Zip  9Drwxrwxr-x5Liul Liul4096Oct9  -: - Install  TenDrwxrwxr-x2Liul Liul4096Oct9  -: -Shell OneDrwxr-xr-x8Liul Liul4096Oct9  at:Wuyiyaml-0.1.4   A-rw-r--r--1Liul Liul471759Sep -  -: -yaml-0.1.4.Tar. GZ - [SQL] View plaincopy -[Email protected] dataload]$ls-L-- Time-style'+%y/%m/%d%h:%m:%s'   theTotal28896   -Drwxr-xr-x8Liul Liul4096  -/ the/ -  -:Ten: -pyyaml-3.10   --rw-r--r--1Liul Liul241524  -/ the/ -  -: +:Tenpyyaml-3.10.Tar. GZ --rwxr-xr-x1Liul Liul14466821  -/ Geneva/ - xx: at: -greenplum-loaders-4.2.1.0-build-2-rhel5-X86_64.bin +-rw-r--r--1Liul Liul14304561  -/Geneva/ on  -: -: -greenplum-loaders-4.2.1.0-build-2-rhel5-x86_64.Zip   -Drwxrwxr-x5Liul Liul4096  -/Ten/ the  -: -:xx Install   +Drwxrwxr-x2Liul Liul4096  -/Ten/ the  -: -: -Shell ADrwxr-xr-x8Liul Liul4096  -/Ten/ the  at:Wuyi: -yaml-0.1.4   at-rw-r--r--1Liul Liul471759  -/ the/ -  -: -: -yaml-0.1.4.Tar. GZ - [SQL] View plaincopy -Add export time_style= to ~/.bash_profile'+%y/%m/%d%h:%m:%s'   -[Email protected] dataload]$VI~/. Bash_profile -[Email protected] dataload]$ source ~/. Bash_profile -[Email protected] dataload]$Cat~/.bash_profile |grep Time inExport time_style='+%y/%m/%d%h:%m:%s'   -[Email protected] dataload]$ source ~/. Bash_profile to[Email protected] dataload]$ls-L +Total28896   -Drwxr-xr-x8Liul Liul4096  -/ the/ -  -:Ten: -pyyaml-3.10   the-rw-r--r--1Liul Liul241524  -/ the/ -  -: +:Tenpyyaml-3.10.Tar. GZ *-rwxr-xr-x1Liul Liul14466821  -/ Geneva/ - xx: at: -greenplum-loaders-4.2.1.0-build-2-rhel5-X86_64.bin $-rw-r--r--1Liul Liul14304561  -/Geneva/ on  -: -: -greenplum-loaders-4.2.1.0-build-2-rhel5-x86_64.Zip  Panax NotoginsengDrwxrwxr-x5Liul Liul4096  -/Ten/ the  -: -:xx Install   -Drwxrwxr-x2Liul Liul4096  -/Ten/ the  -: -: -Shell theDrwxr-xr-x8Liul Liul4096  -/Ten/ the  at:Wuyi: -yaml-0.1.4   +-rw-r--r--1Liul Liul471759  -/ the/ -  -: -: -yaml-0.1.4.Tar. gz

Changes to the Linux environment variables (permanent, temporary) and the time format for modifying the LS display

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.