如何创建 Bash 别名? [英] How do I create a Bash alias?

查看:33
本文介绍了如何创建 Bash 别名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 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.

推荐答案

您可以在启动脚本文件中添加 aliasfunction.通常这是您的主目录中的 .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 infoaliasfunctions 等放入其中.

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:

  1. 启动终端
  2. 输入 cd ~/ 转到您的主文件夹
  3. 输入 touch .bash_profile 以创建新文件.
  4. 使用您喜欢的编辑器编辑 .bash_profile(或者您可以直接输入 open -e .bash_profile 在 TextEdit 中打开它.
  5. 输入<代码>..bash_profile 重新加载 .bash_profile 并更新您添加的任何别名.
  1. Start up Terminal
  2. Type cd ~/ to go to your home folder
  3. Type touch .bash_profile to create your new file.
  4. Edit .bash_profile with your favorite editor (or you can just type open -e .bash_profile to open it in TextEdit.
  5. Type . .bash_profile to reload .bash_profile and update any alias you add.

这篇关于如何创建 Bash 别名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆