简体   繁体   English

什么是 .bashrc - 如何找到启动文件 - putty

[英]what is .bashrc - How to find the startup file - putty

I was going over this article and it states in step 3我正在阅读这篇文章,它在第 3 步中说明

Add the following to your .bashrc (or the appropriate startup file for your shell)  To use it immediately, be sure to type “source .bashrc” 

Any idea on how I could know what my startup file is ?关于如何知道我的启动文件是什么的任何想法? I am using putty ?我在用腻子?

The .bashrc is a file which is called by bash before on each start of a new interactive shell. .bashrc是一个文件,在每次启动新的交互式shell之前由bash调用。 The file can be used to setup the environment, export variables, create aliases and functions and more... 该文件可用于设置环境,导出变量,创建别名和函数等等...

There are usually multiple instances of that file. 该文件通常有多个实例。 One per system and one per user to allow system wide configuration but also customization by users ( users bashrc will be sourced after the system wide bashrc and can overwrite things). 每个系统一个,每个用户一个,允许系统范围的配置,但也允许用户定制(用户bashrc将在系统范围的bashrc之后获取,并且可以覆盖事物)。 I suggest to add the lines to your user's bashrc first. 我建议先将行添加到用户的bashrc中。 The file is located in your home folder. 该文件位于您的主文件夹中。 Type: 类型:

vi $HOME/.bashrc

in order to edit the file. 为了编辑文件。 If you aren't familiar with the vi editor you can choose an editor of your choice like nano , mcedit or even a GUI text editor, but mind that a GUI editor's file dialog may hide the file because it's name starts with a . 如果你不熟悉vi编辑器,你可以选择你喜欢的编辑器,如nanomcedit甚至是GUI文本编辑器,但是请注意,GUI编辑器的文件对话框可能会隐藏文件,因为它的名字以a开头.

Once you managed to edit the file, start a new connection or simply type 设法编辑文件后,启动新连接或只需键入

source $HOME/.bashrc

in order to parse the file 为了解析文件

Once you use putty to SSH into your server, you can run "ls -al .bashrc" and it should show you the file, edit this with an editor you know, if none, then use vi like this "vi .bashrc". 一旦你使用putty到你的服务器SSH,你可以运行“ls -al .bashrc”它应该显示文件,用你知道的编辑器编辑它,如果没有,那么使用像这样的“vi .bashrc”。

Go to where you need to edit the file and type in "i" to put vi in Insert mode. 转到需要编辑文件的位置,然后输入“i”将vi置于插入模式。 Next type in your text. 接下来输入你的文字。 Once you are done press the escape button and ":wq", no quotes for the i or :wq. 完成后按退出按钮和“:wq”,i或wq没有引号。

Next you can source it by typing "source .bashrc" and the setting you added should be part of your BASH shell environment now. 接下来,您可以通过键入“source .bashrc”来获取它,并且您添加的设置现在应该是BASH shell环境的一部分。

无论操作系统如何(macOS / Linux / BSD等),任何bash shell都可以使用的路径是:

~/.bashrc

check your home directory ...because it exists in user's home directory. 检查您的主目录...因为它存在于用户的主目录中。

check /home/username/ on your terminal if you are using RHEL or CentOS. 如果您使用的是RHEL或CentOS,请在终端上检查/ home / username /

.bashrc and .bash_profile are bash config files(bash shell script) that bash runs whenever it is started interactively.It initialize an interactive(non-login) shell session and the config is read from these files $HOME/.bashrc .bashrc 和 .bash_profile 是 bash 配置文件(bash shell 脚本),每当它以交互方式启动时,bash 就会运行它。它初始化一个交互式(非登录)shell 会话,并从这些文件中读取配置 $HOME/.bashrc

For Login shells,the config is read from these files:对于登录 shell,从这些文件中读取配置:

/etc/profile (always sourced) /etc/profile(总是来源)

$HOME/.bash_profile (the rest of these files are checked in order until one is found,then no other are read) $HOME/.bash_profile (这些文件的其余部分按顺序检查,直到找到一个,然后不读取其他文件)

$HOME/.bash_login $HOME/.bash_login

$HOME/.profile $HOME/.profile

For example : I added an echo to my .bashrc and .bash_profile files and whenever i called bash or bash -l command in terminal it showed me the echo例如:我在我的 .bashrc 和 .bash_profile 文件中添加了一个回声,每当我在终端中调用 bash 或 bash -l 命令时,它都会向我显示回声

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM