如何创建 Bash 别名?

编程入门 行业动态 更新时间:2024-10-22 02:41:46
本文介绍了如何创建 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.

推荐答案

您可以在启动脚本文件中添加 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 type open -e .bash_profile to open it in TextEdit.
  • Type . .bash_profile to reload .bash_profile and update any alias you add.
  • 更多推荐

    如何创建 Bash 别名?

    本文发布于:2023-10-26 18:56:17,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1531053.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:别名   Bash

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!