search
HomeCommon Problemwhat 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"

2.设定环境路径

PATH="$PATH:$HOME/.local/bin:$HOME"
export PATH

3.提示符设置

PS1=”[\u: \w]$”

三、.bashrc 怎么用?

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

vim ~/.bashrc

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

1、个性化指令

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

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

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

语法一:

function function_name {
    command1
    command2^>
}

语法二:

function_name () {
 command_1
 command_2
}

语法三

function_name () { command1; command2; }

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

md () {
  mkdir -p $1
  cd $1 
}

也可写成:

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

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

2、路径设置

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

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

#语法二
export PATH=$PATH:路径

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

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

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

source ~/.bashrc

四、.bashrc 没了怎么办?

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

cp /etc/skel/.bashrc ~/

相关推荐:《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
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

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.