[Linux] Detailed introduction and summary of some system files under Linux

One, ~/.bashrc file

Introduction

  • The .bashrc file is a script file in the Linux system. Its main function is to automatically execute a series of commands and set environment variables when the user logs in to the shell. It is usually located in the user's home directory, and the file name is ".bashrc", which is a personalized configuration file that can be modified by each user.
  • When a user logs in to the system, the bash shell first tries to read and execute the global settings in the /etc/profile file. Then, read the corresponding user personal configuration file according to the user's identity, including the .bashrc file.
  • The commands and settings in the .bashrc file are usually used to customize the user's shell environment, for example, defining aliases (alias), setting environment variables, importing function libraries, configuring prompts, and so on. You can freely edit the .bashrc file to configure the shell according to your needs. The contents of the .bashrc file are loaded and executed each time the user opens a new terminal session.

Here are some settings and commands common to .bashrc files

  1. Setting environment variables: You can use the export command to set environment variables.
  2. Define command aliases: By using the alias command, you can create aliases to simplify the use of commonly used commands.
  3. Setting up the command prompt: You can use the PS1 environment variable to customize the shell's prompt.
    1. export PS1="\[\033[32m\][\u@\h \W]\$\[\033[0m\] "
    2. The above command sets the prompt to green, showing the current username (\u), hostname (\h), and current working directory (\W). The effect is as follows
  4. Import function library: If you have some commonly used functions, you can put them in a separate script file, and then use the source command in the .bashrc file to import.
    1. source ~/scripts/myfunctions.sh
  5. Set command line history: With the HISTSIZE variable, you can specify the number of lines of history to keep in memory. And the HISTFILESIZE variable is used to specify the number of history rows to keep on disk.
  6. Adjust command-line autocompletion behavior: The following code enables the bash-completion extension, which provides autocompletion for commands and paths. By loading the bash_completion script, you can get a more powerful and convenient command line input experience.
  7. Automatically execute commands or scripts: The following code checks for the existence of the .autostart file in the .bashrc file and automatically executes the commands or scripts in it when the user logs in. ( You can add commands or scripts that need to be automatically executed at login in the .autostart file )

Second, the follow-up continuous update

Guess you like

Origin blog.csdn.net/weixin_43729127/article/details/132138022