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


当前回答

在root - ex用户下创建bash_profile

/user/username/.bash_profile

打开的文件

vim ~ / . bash_profile

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

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

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

/user/username/Documents/dirname/anotherdir

其他回答

它适用于我的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

完成了。使用并享受!

我只是打开zshrc与sublime,并编辑它。

subl .zshrc

在sublime上加上这个:

alias blah="/usr/bin/blah"

在terminal中执行如下命令:

source ~/.zshrc

完成了。

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

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

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

MacOS卡特琳娜及以上

苹果将默认shell转换为zsh,因此配置文件包含~/。Zshenv和~/.zshrc。这就像~/。Bashrc,但zsh。只需编辑文件并添加您需要的内容;每次打开一个新的终端窗口时,都应该引用它:

纳米~ - zshenv。 别名py = python)

然后按ctrl+x, y,然后输入保存。

该文件似乎无论在什么情况下(登录、非登录或脚本)都要执行,因此似乎比~/更好。zshrc中。

高海拔及更早

默认shell是bash,您可以编辑文件~/。Bash_profile和添加别名:

纳米~ / . bash_profile 别名py = python

然后按ctrl+x, y, enter保存。有关这些配置的更多信息,请参阅这篇文章。在~/中使用别名设置会更好一些。Bashrc,然后source ~/。~/.bash_profile中的Bashrc。在~ /。Bash_profile看起来就像这样:

来源 ~/.巴什尔克

您可能希望在主目录中编辑.bashrc文件。