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


当前回答

在我的.bashrc文件中,默认存在以下行:

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

因此,在我的平台中.bash_aliases是默认情况下用于别名的文件(也是我使用的文件)。我不是OS X用户,但我猜如果你打开你的.bashrc文件,你就能识别出平台中常用的别名文件是什么。

其他回答

我需要运行Postgres数据库并为此目的创建一个别名。具体工作思路如下:

$ nano ~/.bash_profile 

# in the bash_profile, insert the following texts:

alias pgst="pg_ctl -D /usr/local/var/postgres start"
alias pgsp="pg_ctl -D /usr/local/var/postgres stop"


$ source ~/.bash_profile 

### This will start the Postgres server 
$ pgst

### This will stop the Postgres server 
$ pgsp

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

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

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

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

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

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

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

subl .zshrc

在sublime上加上这个:

alias blah="/usr/bin/blah"

在terminal中执行如下命令:

source ~/.zshrc

完成了。

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

完成了。使用并享受!