Linux environment configuration file ----. Bashrc file (rpm) Linux environment configuration file ----. Bashrc file

Linux environment configuration file ----. Bashrc file

 

The main .bashrc file saved some personal personalized settings, such as command aliases, path and so on. That is on the same server, only relevant to a user's personalized settings. It is a hidden file, use ls -a to see.

  .bash_history record previously entered commands

   .Bash_logout command executed when you exit

   .bash_profile is executed when you login shell

   .bashrc is executed when you login shell

  The difference between the two: '. Bash_profile' is read only once during a session at the start of the '.bashrc' is opened each time a new terminal is to be read.

      These files are for every user terminal functions and property settings, modify environment variables can be changed .bashrc PATH, alias alias and prompt. How do specific changes will be described below.

      In addition to editing the user directory files .bashrc outer can also be modified, such as "/ etc / profile" file, the file "/ etc / bashrc" file and directory "/ etc /profile.d". But modify / etc directory in the configuration file will be applied to the whole system, belonging to the system-wide configuration, modifying .bashrc user's directory is only limited in the user application, the user belongs to the set level. Both differ in the scope of application, it is recommended To modify it, modify .bashrc in the user directory, ie without root privileges, it will not affect other users.

Modify the PATH environment variable

       PATH variable determines the shell which directories to find commands or programs. If the directory command to be executed in the $ PATH, you do not have to enter the full path of the command, enter the command directly on it. Some third-party software is not executable files on Linux standard catalog. Therefore, adding these non-standard installation directory to your $ PATH is a solution. In addition, you will see how to deal with the general environment variables.

First of all, as a rule, all environment variable names are capitalized. Because Linux is case sensitive, you want to pay attention to this point. Of course, you can define your own variables, such as '$ path', '$ pAtH', but the shell will not ignore these variables.

The second point is sometimes variable name with a '$' at the beginning, but sometimes not. When setting a variable with the name directly, without the need to add "$", such as

“PATH=/usr/bin:/usr/local/bin:/bin”

If you want to get the value of a variable, then you would add the variable name with '$': ": / usr / local / bin: / bin / usr / bin" "echo $ PATH" PATH variable is currently set is displayed

Otherwise, the variable name will be treated as a plain text: "echo PATH" show the third point "PATH" $ PATH variable processing should be noted that: You can not just replace a variable, but you want to add a new string the original values. In most cases, you can not use the "PATH = / some / directory", because this will remove $ PATH in all other directories, so when you run the terminal program, you have to give the full path. So, can only be added: "PATH = $ PATH: / some / directory", if you want to add /usr/local/arm/3.4.1/bin cross compiler command, the operation is "PATH = $ PATH: / usr /local/arm/3.4.1/bin "Thus, PATH is set to the current value (expressed in $ PATH) + newly added directory.

So far, you just set up a new $ PATH variable for the current terminal. If you open a new terminal, run echo $ PATH, will show the old value of $ PATH, but you just can not see the new directory added. Because you previously defined a local environment variable (limited to the current terminal).

To define a global variable that takes effect after the terminal opened, you will need a local variable output (export), you can use "export" command:

       export PATH=$PATH:/some/directory

Now if you open a new terminal and type echo $ PATH, $ PATH can see the newly set up. Note that the command 'export' can only change the current terminal and terminal operation later in the variables. For the terminal is already running has no effect.

       In order to permanently add the directory to $ PATH, just add the "export" of that line to the .bashrc or / etc / bashrc file.

  Use the command:

  sudo gedit ~/.bashrc

Aliases

       There are generally a few words in .bashrc or / etc / bashrc file

       alias rm = 'rm -i'

       alias cp = 'cp -i'

       alias etc. = 'etc. -i'

       With these words, when the input in the terminal "mv test.c led.c" actually enter is "mv -i test.c led.c", so that the alias is an alias. You can add your own style in the configuration file aliases, such as "alias ll = 'ls -l'", just type "ll" to achieve the "ls -l" function in the terminal. You can also add other statements, with their own preferences.

 Prompt

  When you open a console (console), is the first to see the prompt (prompt), such as: [root @ localhost ~] #

  In the default setting, the prompt will display the user name, host name (the default is 'localhost'), the current directory (on Unix, '~' represents your home directory). According to tradition, the last character can identify normal user ($), or 'root' (#). You can be set up by $ PS1 prompt variable.

  Command "echo $ PS1", the current setting is displayed. Wherein the available characters in the meaning of the man bash 'PROMPTING' portion of a note.

How to complete the ideal setting it? For the forgetful beginners, the default setting somewhat unfriendly, because prompt only the last part of the current directory. If you see a prompt like this

      [Wsf @ localhost bin] $ may be the current directory '/ bin', '/ usr / bin', '/ usr / local / bin' and '/ usr / X11R6 / bin'. Of course, you can use

pwd (output current directory, print working directory)

You can not call the shell to tell you the current directory it?

of course can. Here I will mention settings, including prompt, mostly contained in the file '/ etc / bashrc' in. You can change the settings by editing their home directory under '.bash_profile' and '.bashrc'.

In the man bash 'PROMPTING' section, a detailed description of the parameters (parameter). You can add some gadgets, such as the current time in different formats, command history record number, and even different colors.

A more appropriate settings: PS1 = "[\ u: \ w] \\ $" Thus, the prompt becomes: [wsf: / usr / bin] $ You can test different settings command export ( For example, export PS1 = "\ u: \ w \\ $"). If you find a suitable prompt, it will set into your '.bashrc' 'in. In this way, every time you open a console or terminal window, will take effect.

Reference https://www.cnblogs.com/testlife007/p/6548698.html

The main .bashrc file saved some personal personalized settings, such as command aliases, path and so on. That is on the same server, only relevant to a user's personalized settings. It is a hidden file, use ls -a to see.

  .bash_history record previously entered commands

   .Bash_logout command executed when you exit

   .bash_profile is executed when you login shell

   .bashrc is executed when you login shell

  The difference between the two: '. Bash_profile' is read only once during a session at the start of the '.bashrc' is opened each time a new terminal is to be read.

      These files are for every user terminal functions and property settings, modify environment variables can be changed .bashrc PATH, alias alias and prompt. How do specific changes will be described below.

      In addition to editing the user directory files .bashrc outer can also be modified, such as "/ etc / profile" file, the file "/ etc / bashrc" file and directory "/ etc /profile.d". But modify / etc directory in the configuration file will be applied to the whole system, belonging to the system-wide configuration, modifying .bashrc user's directory is only limited in the user application, the user belongs to the set level. Both differ in the scope of application, it is recommended To modify it, modify .bashrc in the user directory, ie without root privileges, it will not affect other users.

Modify the PATH environment variable

       PATH variable determines the shell which directories to find commands or programs. If the directory command to be executed in the $ PATH, you do not have to enter the full path of the command, enter the command directly on it. Some third-party software is not executable files on Linux standard catalog. Therefore, adding these non-standard installation directory to your $ PATH is a solution. In addition, you will see how to deal with the general environment variables.

First of all, as a rule, all environment variable names are capitalized. Because Linux is case sensitive, you want to pay attention to this point. Of course, you can define your own variables, such as '$ path', '$ pAtH', but the shell will not ignore these variables.

The second point is sometimes variable name with a '$' at the beginning, but sometimes not. When setting a variable with the name directly, without the need to add "$", such as

“PATH=/usr/bin:/usr/local/bin:/bin”

If you want to get the value of a variable, then you would add the variable name with '$': ": / usr / local / bin: / bin / usr / bin" "echo $ PATH" PATH variable is currently set is displayed

Otherwise, the variable name will be treated as a plain text: "echo PATH" show the third point "PATH" $ PATH variable processing should be noted that: You can not just replace a variable, but you want to add a new string the original values. In most cases, you can not use the "PATH = / some / directory", because this will remove $ PATH in all other directories, so when you run the terminal program, you have to give the full path. So, can only be added: "PATH = $ PATH: / some / directory", if you want to add /usr/local/arm/3.4.1/bin cross compiler command, the operation is "PATH = $ PATH: / usr /local/arm/3.4.1/bin "Thus, PATH is set to the current value (expressed in $ PATH) + newly added directory.

So far, you just set up a new $ PATH variable for the current terminal. If you open a new terminal, run echo $ PATH, will show the old value of $ PATH, but you just can not see the new directory added. Because you previously defined a local environment variable (limited to the current terminal).

To define a global variable that takes effect after the terminal opened, you will need a local variable output (export), you can use "export" command:

       export PATH=$PATH:/some/directory

Now if you open a new terminal and type echo $ PATH, $ PATH can see the newly set up. Note that the command 'export' can only change the current terminal and terminal operation later in the variables. For the terminal is already running has no effect.

       In order to permanently add the directory to $ PATH, just add the "export" of that line to the .bashrc or / etc / bashrc file.

  Use the command:

  sudo gedit ~/.bashrc

Aliases

       There are generally a few words in .bashrc or / etc / bashrc file

       alias rm = 'rm -i'

       alias cp = 'cp -i'

       alias etc. = 'etc. -i'

       With these words, when the input in the terminal "mv test.c led.c" actually enter is "mv -i test.c led.c", so that the alias is an alias. You can add your own style in the configuration file aliases, such as "alias ll = 'ls -l'", just type "ll" to achieve the "ls -l" function in the terminal. You can also add other statements, with their own preferences.

 Prompt

  When you open a console (console), is the first to see the prompt (prompt), such as: [root @ localhost ~] #

  In the default setting, the prompt will display the user name, host name (the default is 'localhost'), the current directory (on Unix, '~' represents your home directory). According to tradition, the last character can identify normal user ($), or 'root' (#). You can be set up by $ PS1 prompt variable.

  Command "echo $ PS1", the current setting is displayed. Wherein the available characters in the meaning of the man bash 'PROMPTING' portion of a note.

How to complete the ideal setting it? For the forgetful beginners, the default setting somewhat unfriendly, because prompt only the last part of the current directory. If you see a prompt like this

      [Wsf @ localhost bin] $ may be the current directory '/ bin', '/ usr / bin', '/ usr / local / bin' and '/ usr / X11R6 / bin'. Of course, you can use

pwd (output current directory, print working directory)

You can not call the shell to tell you the current directory it?

of course can. Here I will mention settings, including prompt, mostly contained in the file '/ etc / bashrc' in. You can change the settings by editing their home directory under '.bash_profile' and '.bashrc'.

In the man bash 'PROMPTING' section, a detailed description of the parameters (parameter). You can add some gadgets, such as the current time in different formats, command history record number, and even different colors.

A more appropriate settings: PS1 = "[\ u: \ w] \\ $" Thus, the prompt becomes: [wsf: / usr / bin] $ You can test different settings command export ( For example, export PS1 = "\ u: \ w \\ $"). If you find a suitable prompt, it will set into your '.bashrc' 'in. In this way, every time you open a console or terminal window, will take effect.

Reference https://www.cnblogs.com/testlife007/p/6548698.html

Guess you like

Origin www.cnblogs.com/lh03061238/p/11106002.html
Recommended