Detailed explanation of Linux /etc/profile file and how to take effect immediately after modification

The change of the Linux /etc/profile file will involve the system environment, that is, things related to Linux environment variables. To learn Linux, you need to understand the relevant principles of the Linux profile file. Here, the file is analyzed in detail. This modification will work for all users.

  1. Linux is a multi-user operating system. After each user logs in to the system, there will be a dedicated operating environment. Usually the default environment of each user is the same, and this default environment is actually the definition of a set of environment variables. Users can customize their own operating environment by modifying the corresponding system environment variables.

  2. The environment variables are often modified in the /etc/profile file, and the content modified here is effective for all users. The following main operations will be performed in this file.

  3. How to add environment variables.

  For example add "NAME=liheng". Add the following at the end of the profile file export NAME=liheng

  The variable value liheng can be enclosed in quotation marks or not, and the effect is the same.

  4 (1), the content added or modified in the profile file needs to log out of the system to take effect.

      4 (2) How to modify the profile file in Linux system to take effect immediately?

    method 1:
        To make the /etc/profile file take effect immediately after modification, you can use the following command:
        # .  /etc/profile
        Note: . and /etc/profile have spaces
    Method 2:
        To make the /etc/profile file take effect immediately after modification, you can use the following command:
        # source /etc/profile

    Attachment: Usage of source command in Linux
        source command:
        The source command is also known as the "dot command", which is a dot notation (.). The source command is usually used to re-execute the just-modified initialization file to take effect immediately without having to log out and back in.
        usage:
        source filename 或 . filename

  5. How to understand the repeated definition of variables.

  A frequent occurrence is the definition of the PATH variable.

  For example: in the peofile file, the PATH variable is set to PATH=¥¥¥¥¥¥¥ by default (can’t remember), and it may be set to the PATH in the future, which is usually added to the last PATH=... · · (for example). In the system, the identified PATH=·······¥¥¥¥¥¥¥¥¥, that is to say, the environment variables with the same name will work first (in layman’s terms). Everyone must pay attention.

  6. Introduction of special characters.

  For example, there is the following content in the profile, and the usage of special symbols is explained by the following content.

  export A=/q/jing:aaa/cc/ld

  export B =.: /iheng / wang export A = / cd / cdr: $ A

  Pay attention to the red symbols:

  : Indicates parallel meanings. For example, if there are multiple A variable values, use the : symbol to separate them.

  . Indicates the current directory you are working on. For example the pap command will look for the B environment variable.

  Type the pap command in /home, the system will first look for the content of B in the /home directory (ie the current path), if linuxidc.com">www.linuxidc.com does not look for the content of B in the /liheng/wang directory. $ represents the value of the variable before this definition, for example, $A represents /q/jing:aaa/cc/ld. That is to say, A=/cd/cdr:/q/jing:aaa/cc/ld

  7. Use the env command to display all environment variables. Just type env at the command prompt.

  The set command displays all locally defined shell variables.

  8. Common environment variables

  PATH: determines which directories the shell will look for commands or programs in

  HOME: current user home directory

  MAIL: refers to the current user's mail storage directory.

  SHELL: It refers to which kind of Shell the current user is using.

  HISTSIZE: refers to the number of historical command records saved.

  LOGNAME: refers to the login name of the current user.

  HOSTNAME: refers to the name of the host, if many applications use the host name, it is usually obtained from this environment variable.

  LANG/LANGUGE: It is a language-related environment variable. Users who use multiple languages ​​can modify this environment variable.

  PS1: is the basic prompt, which is # for root users and $ for ordinary users.

  PS2: It is an auxiliary prompt, the default is ">". You can modify the current command line by modifying this environment variable. For example, the following command will modify the prompt to the string "Hello,My NewPrompt :) ".

  # PS1=” Hello,My NewPrompt :) “

  9. Use the modified .bashrc file (in the user's home directory) to edit the environment variables, which is only useful for the current user. Editing environment variables by modifying the /etc/profile file is useful for all users. Everyone must pay attention to the difference .

  10. The Linux profile file will be run when the system starts. You can add other commands in it, but you must add them correctly, otherwise the system will not start.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324968335&siteId=291194637