Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the function of bashrc and profile files in Linux system

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail about the role of bashrc and profile files in the Linux system, the content of the article is of high quality, so the editor will share it for you to do a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

After logging in to the console of the Linux operating system using the terminal ssh, a prompt symbol (for example: # or ~) appears. After this prompt symbol, you can enter a command, and Linux will respond according to the command entered. This series of actions are handled by a so-called Shell.

Shell is a program, the most commonly used is Bash, which is also the default Shell used by the login system.

Both bashrc and profile are startup settings files for Shell (in fact, these two files are also Shell scripts), which can initialize environment variables for the current Shell, and so on, which are similar to the autoexec.bat files under Microsoft DOS/Windows.

The uses and differences between bashrc and profile are described in detail below:

For individual users

User HOME (home) directory / .bashrc

The code is as follows:

# ~ / .bashrc: executed by bash (1) for non-login shells

# ~ / .bashrc: executed by bash (1) for non-login shells

User HOME (home) directory / .profile

The code is as follows:

# ~ / .profile: executed by Bourne-compatible login shells

# ~ / .profile: executed by Bourne-compatible login shells

For all users

The code is as follows:

/ etc/bash.bashrc

# System-wide .bashrc file for interactive bash (1) shells.

/ etc/profile

# / etc/profile: system-wide .profile file for the Bourne shell (sh (1)

The code is as follows:

/ etc/bash.bashrc

# System-wide .bashrc file for interactive bash (1) shells.

/ etc/profile

# / etc/profile: system-wide .profile file for the Bourne shell (sh (1)

The difference between bashrc and profile

As can be seen from the English description above, the difference between bashrc and profile lies in:

1. Bashrc runs automatically after the system starts.

2. Profile will not run until the user logs in.

3. After setting up, you can use the source bashrc command to update bashrc, or you can use the source profile command to update profile.

PS: usually we modify bashrc. Some distributions of linux do not necessarily have the file profile.

4. The variable (global) set in / etc/profile can act on any user, while the variable (local) set in ~ / .bashrc and so on can only inherit the variable in / etc/profile, they are "father-son" relationship.

To figure out the difference between bashrc and profile, you first need to figure out what is interactive shell and non-interactive shell, and what are login shell and non-login shell.

Interactive mode is where shell waits for your input and executes the commands you submit. This mode is called interactive because shell interacts with users. This mode is also familiar to most users: log in, execute some commands, and sign out. When you sign out, shell is terminated. Shell can also run in another mode: non-interactive mode. In this mode, shell does not interact with you, but reads commands stored in the file and executes them. When it reads the end of the file, the shell terminates.

Both bashrc and profile are used to save the user's environment information, bashrc is used for interactive non-loginshell, and profile is used for interactive loginshell. There are many bashrc and profile files in the system, which are described one by one:

/ etc/pro this file sets environment information for each user of the system and is executed when the first user logs in.

And collect shell settings from the configuration file in the / etc/profile.d directory.

/ etc/bashrc: execute this file for each user running bash shell. When bash shell is opened, the file is read. The bashrc file is no longer available in the / etc directory in some linux versions.

~ /. Pro each user can use this file to enter shell information dedicated to their own use, and when the user logs in, the

The file is executed only once! By default, it sets some environment variables and then executes the user's .bashrc file.

~ / .bashrc: this file contains bash information specific to a user's bash shell, which is read when the user logs in and each time a new shell is opened.

In addition, the variables (global) set in / etc/profile can act on any user, while the variables (local) set in ~ / .bashrc and so on can only inherit the variables in / etc/profile, they are "father-son" relationship.

Supplementary introduction

In addition, additional notes are needed to introduce several files related to bashrc:

~ / .bash_profile: each user can use this file to enter shell information dedicated to their own use. When the user logs in, the file is executed only once! By default, he sets some environment variables to execute the user's .bashrc file.

~ / .bash_logout: this file is executed each time you exit the system (exit bash shell).

~ / .bash_profile is interactive, login mode into the bash operation, ~ / .bashrc is interactive non-login mode into the bash operation, usually the two settings are roughly the same, so usually the former will call the latter.

On the role of bashrc and profile files in the Linux system is shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report