Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the difference between bashrc and profile in linux

Shulou Source: shulou.com Published: 2022-06-01 14:49:08 09月15日 Update

Xiaobian to share with you what is the difference between bashrc and profile in linux, I hope you have gained something after reading this article, let's discuss it together!

To understand the difference between a bashrc and a profile, first understand what an interactive shell is and what a non-interactive shell is, and what a login shell is and what a non-login shell is.

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

Startup profiles for individual users

User HOME Directory/.bashrc

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

User HOME Directory/.profile

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

Startup profile for all users

head -1 /etc/bash.bashrc# System-wide .bashrc file for interactive bash(1) shells.head -2 /etc/profile# /etc/profile: system-wide .profile file for the Bourne shell (sh(1)# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

Differences between bashrc and profile

The difference between bashrc and profile is: 1. bashrc is automatically run after system startup. 2. Profile is not run until the user logs in. 3. After setting, you can update bashrc with the source bashrc command or update profile with the source profile command. PS: Usually we modify bashrc, some linux distributions do not necessarily have this file profile, the system used in this article is Ubuntu 15.104. The variables (global) set in/etc/profile can be applied to any user, while the variables (local) set in ~/.bashrc can only inherit the variables in/etc/profile, and they are "parent-child" relationships. After reading this article, I believe you have a certain understanding of "what is the difference between bashrc and profile in linux". If you want to know more about it, welcome to pay attention to the industry information channel. Thank you for reading!

Tags: User mode interactive command file variable run difference is in directory article system central transportable update login configuration function global finished Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn OPPO Reno Shulou Information MySQL Docker