我在OSX上,我需要把这样的东西,别名blah=“/usr/bin/blah”在配置文件中,但我不知道配置文件在哪里。


当前回答

它适用于我的macOS Mojave

你可以做一些简单的步骤:

open terminal sudo nano /.bash_profile add your aliases, as example: some aliases alias ll='ls -alF' alias la='ls -A' alias eb="sudo nano ~/.bash_profile && source ~/.bash_profile" #docker aliases alias d='docker' alias dc='docker-compose' alias dnax="docker rm $(docker ps -aq)" #git aliases alias g='git' alias new="git checkout -b" alias last="git log -2" alias gg='git status' alias lg="git log --pretty=format:'%h was %an, %ar, message: %s' --graph" alias nah="git reset --hard && git clean -df" alias squash="git rebase -i HEAD~2" source /.bash_profile

完成了。使用并享受!

其他回答

您可以在启动脚本文件中添加别名或函数。通常是主目录下的.bashrc、.bash_login或.profile文件。

由于这些文件是隐藏的,您必须执行ls -a命令来列出它们。如果你没有,你可以创建一个。


如果我没记错的话,当我买了我的Mac时,.bash_login文件并不在那里。我必须为自己创建它,这样我就可以把提示信息、别名、函数等放在里面。

如果你想创建一个,以下是步骤:

启动终端 输入cd ~/进入主文件夹 输入touch .bash_profile创建新文件。 使用您喜欢的编辑器编辑.bash_profile(或者您可以键入open -e .bash_profile在TextEdit中打开它。 输入. .bash_profile重新加载.bash_profile并更新您添加的任何别名。

在root - ex用户下创建bash_profile

/user/username/.bash_profile

打开的文件

vim ~ / . bash_profile

添加别名为ex.(保存并退出)

alias mydir="cd ~/Documents/dirname/anotherdir"

在新终端中输入mydir -它应该会打开

/user/username/Documents/dirname/anotherdir

脚本和程序的配置文件是~/。bashrc和使用Terminal时加载的配置文件是~/.bash_login。

我认为最好的方法是把所有东西都放在~/.bashrc中。

对于您的特定问题,只需输入(这将覆盖任何现有的~/.bashrc):

echo "alias blah=\"/usr/bin/blah\"" >>~/.bashrc

输入终端和~/。Bashrc文件将与您的新别名一起创建。之后,只需编辑文件,添加新的别名,函数,设置等。

macOS Catalina用户:

步骤1:创建或更新.zshrc文件

vi ~/.zshrc

步骤2:添加别名行

alias blah="/usr/bin/blah"

步骤3:源.zshrc

source ~/.zshrc 

步骤4:通过在命令提示符上输入alias来检查您的别名

alias

在OS X上,你需要使用~/.bash_profile。这是因为默认终端。应用程序为每个新窗口打开一个登录shell。

查看更多关于不同的配置文件以及何时使用它们的信息: .bashrc, .bash_profile和.environment之间有什么区别?

和在OSX这里:关于.bash_profile, .bashrc,别名应该写在哪里?