当前位置:   article > 正文

Linux中.bashrc文件是什么?

.bashrc

The .bashrc file is a script file that’s executed when a user logs in. The file itself contains a series of configurations for the terminal session. This includes setting up or enabling: coloring, completion, shell history, command aliases, and more.

.bashrc文件是用户登录时执行的脚本文件。该文件本身包含终端会话的一系列配置。 这包括设置或启用:着色,完成,shell历史记录,命令别名等。

It is a hidden file and simple ls command won’t show the file.

这是一个隐藏文件 ,简单的ls命令不会显示该文件。

To view hidden files, you can run the below command:

要查看隐藏的文件,可以运行以下命令:


$ ls -a

  • 1
  • 2
  • 3

http://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4uam91cm5hbGRldi5jb20vd3AtY29udGVudC91cGxvYWRzLzIwMjAvMDYvbHMtYS1jb21tYW5kLnBuZw?x-oss-process=image/format,png

You can see the .bashrc command in the first column. The contents of .bashrc can be changed to define functions, command aliases, and customize the bash.

您可以在第一列中看到**.bashrc命令。 可以更改.bashrc**的内容以定义函数,命令别名和自定义bash。

.bashrc file has a lot of comments that makes it easy to understand.

.bashrc文件包含很多注释,使它易于理解。

To view the bashrc file:

要查看bashrc文件:


$ cat .bashrc

  • 1
  • 2
  • 3

http://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4uam91cm5hbGRldi5jb20vd3AtY29udGVudC91cGxvYWRzLzIwMjAvMDYvY2F0LWJhc2hyYy0xLnBuZw?x-oss-process=image/format,png

A few examples of editing .bashrc are provided below.

下面提供了一些编辑.bashrc的示例。

在bashrc中定义函数 (Defining functions in bashrc)

bashrc can be used to define functions that reduce redundant efforts. These functions can be a collection of basic commands. These functions can even use arguments from the terminal.

bashrc可用于定义减少冗余工作的功能。 这些功能可以是基本命令的集合。 这些函数甚至可以使用终端中的参数。

Let’s define a function that tells the date in a more descriptive manner.

让我们定义一个以更具描述性的方式告诉日期的函数。

First you’ll need to enter the .bashrc file in editing mode.

首先,您需要在编辑模式下输入.bashrc文件。


$ vi .bashrc

  • 1
  • 2
  • 3

Bashrc FileBashrc文件

http://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4uam91cm5hbGRldi5jb20vd3AtY29udGVudC91cGxvYWRzLzIwMjAvMDYvYmFzaHJjLWZpbGUtLnBuZw?x-oss-process=image/format,png

This is what the terminal will look like. To start editing press any letter on the keyboard. At the end of the file add the following code:

这就是终端的外观。 要开始编辑,请按键盘上的任意字母。 在文件末尾添加以下代码:


today()
{
    echo This is a `date +"%A %d in %B of %Y (%r)"` return
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

Press escape. Then to save and exit from vi, press colon (

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/51182
推荐阅读
相关标签