Home Common Problem what is linux bashrc

what is linux bashrc

Mar 02, 2023 am 09:51 AM
linux

在linux中,bashrc是home目录下的一个shell文件,用于储存用户的个性化设置。在bash每次启动时都会加载bashrc文件中的内容,并根据内容定制当前bash的配置和环境。bashrc的作用:1、可以在利用命名函数alias定制需要的指令;2、设定环境路径;3、提示符设置。

what is linux bashrc

本教程操作环境:linux7.3系统、Dell G3电脑。

一、.bashrc 是什么?

.bashrc是home目录下的一个shell文件,用于储存用户的个性化设置。在bash每次启动时都会加载.bashrc文件中的内容,并根据内容定制当前bash的配置和环境。

补充.bash_profile.bashrc的区别?
两者在登陆bash时都会被bash执行,但是.bash_profile只在会话开始时被读取,而.bashrc在每次打开新的终端时都会被读取。

二、.bashrc 能干什么?

1.个性化指令

alias ll = "ls -lha"
Copy after login

2.设定环境路径

PATH="$PATH:$HOME/.local/bin:$HOME"
export PATH
Copy after login

3.提示符设置

PS1=”[\u: \w]$”
Copy after login

三、.bashrc 怎么用?

可以用任何终端文本编辑器打开.bashrc。以vim为例:

vim ~/.bashrc
Copy after login

编辑.bashrc需要遵循bash脚本格式

1、个性化指令

打开.bashrc后,可以在利用命名函数alias定制需要的指令,如

#用 ll 代替 ls -lha 这个命令,在此bash下输入命令 ll 等
#同于输入 ls -lha 命令
alias ll = "ls -lha"
Copy after login

除了缩短命名,也可以用bash函数组合多个命令到一个操作,这些命令大多遵循以下语法。

语法一:

function function_name {
    command1
    <^>command2</^>
}
Copy after login

语法二:

function_name () {
 command_1
 command_2
}
Copy after login

语法三

function_name () { command1; command2; }
Copy after login

下面的命令组合了mkdircd命令,输入md folder_name不仅可以在你的工作目录创建一个名为"folder_name"的目录且进入其中,代码如下:

md () {
  mkdir -p $1
  cd $1 
}
Copy after login

也可写成:

md () {  mkdir -p $1; cd $1; }
Copy after login

其余指令可以参考.bashrc个性化指令推荐

2、路径设置

每次export路径太麻烦,把路径加入到.bashrc是一个一劳永逸的方法,常见的设置语法如下:

#软件名-版本号
#语法一
PATH=$PATH:路径
export PATH

#语法二
export PATH=$PATH:路径
Copy after login

上述语法可以理解为,在原来PATH的后面继续添加了新的路径,在运行特定指令时,系统会逐个位置去寻找文件。 $PATH 表示原先设定的路径,不能遗漏。不同于DOS/Windows,Unix类系统的环境变量的路径用冒号:分割,而不是分号;。为避免环境变量过多产生混乱,建议所有语句都添加在文件结尾,并添加注释。

所有环境变量名都是大写,Linux区分大小写

你对 .bashrc 所做的任何修改将在下一次启动终端时生效。如果你想立刻生效的话,运行下面的命令:

source ~/.bashrc
Copy after login

四、.bashrc 没了怎么办?

首先,首先,首先,.bashrc可以删除,但是删除不存在任何好处。
如果用户删除了.bashrc,可以从如下路径拷贝一份原始的.bashrc文件到用户home目录下

cp /etc/skel/.bashrc ~/
Copy after login

相关推荐:《Linux视频教程

The above is the detailed content of what is linux bashrc. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1253
24
Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

vscode Previous Next Shortcut Key vscode Previous Next Shortcut Key Apr 15, 2025 pm 10:51 PM

VS Code One-step/Next step shortcut key usage: One-step (backward): Windows/Linux: Ctrl ←; macOS: Cmd ←Next step (forward): Windows/Linux: Ctrl →; macOS: Cmd →

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

How to run sublime after writing the code How to run sublime after writing the code Apr 16, 2025 am 08:51 AM

There are six ways to run code in Sublime: through hotkeys, menus, build systems, command lines, set default build systems, and custom build commands, and run individual files/projects by right-clicking on projects/files. The build system availability depends on the installation of Sublime Text.

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

laravel installation code laravel installation code Apr 18, 2025 pm 12:30 PM

To install Laravel, follow these steps in sequence: Install Composer (for macOS/Linux and Windows) Install Laravel Installer Create a new project Start Service Access Application (URL: http://127.0.0.1:8000) Set up the database connection (if required)

git software installation git software installation Apr 17, 2025 am 11:57 AM

Installing Git software includes the following steps: Download the installation package and run the installation package to verify the installation configuration Git installation Git Bash (Windows only)