如何创建 Bash 别名? [英] How do I create a Bash alias?
问题描述
我在 OSX 上,我需要在配置文件中添加类似 alias blah="/usr/bin/blah"
的内容,但我不知道配置文件在哪里.
I'm on OSX and I need to put something like this, alias blah="/usr/bin/blah"
in a config file but I don't know where the config file is.
推荐答案
您可以在启动脚本文件中添加 alias
或 function
.通常这是您的主目录中的 .bashrc
、.bash_login
或 .profile
文件.
You can add an alias
or a function
in your startup script file. Usually this is .bashrc
, .bash_login
or .profile
file in your home directory.
由于这些文件是隐藏的,因此您必须执行 ls -a
来列出它们.如果你没有,你可以创建一个.
Since these files are hidden you will have to do an ls -a
to list them. If you don't have one you can create one.
如果我没记错的话,当我购买 Mac 时,.bash_login
文件并不存在.我必须为自己创建它,以便我可以将 prompt info
、alias
、functions
等放入其中.
If I remember correctly, when I had bought my Mac, the .bash_login
file wasn't there. I had to create it for myself so that I could put prompt info
, alias
, functions
, etc. in it.
如果您想创建一个,请执行以下步骤:
Here are the steps if you would like to create one:
- 启动终端
- 输入
cd ~/
转到您的主文件夹 - 输入
touch .bash_profile
以创建新文件. - 使用您喜欢的编辑器编辑
.bash_profile
(或者您可以直接输入open -e .bash_profile
在 TextEdit 中打开它. - 输入<代码>..bash_profile 重新加载
.bash_profile
并更新您添加的任何别名.
- Start up Terminal
- Type
cd ~/
to go to your home folder - Type
touch .bash_profile
to create your new file. - Edit
.bash_profile
with your favorite editor (or you can just typeopen -e .bash_profile
to open it in TextEdit. - Type
. .bash_profile
to reload.bash_profile
and update any alias you add.
这篇关于如何创建 Bash 别名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!