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


当前回答

我认为这是正确的方式:

1)去终点站。开放的~ / . bashrc。如果不存在则添加

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

2)打开~/.bash_aliases。如果不存在:touch ~/。打开~/.bash_aliases &&

3)增加新的别名 -编辑.bash_aliases文件并重启终端或打印source ~/.bash_aliases - print echo "alias clr='clear'" >> ~/。Bash_aliases && source ~/。Bash_aliases你的别名是别名clr='clear'。

4)添加行源~/。bash_alias到~/。bash_profile文件。它需要在终端的每个init中加载别名。

其他回答

要创建永久别名快捷方式,请将其放在.bash_profile文件中,并将.bashrc文件指向.bash_profile文件。遵循以下步骤(我正在创建一个名为bnode的别名命令来在ES6代码上运行babel transpiler):

Go to terminal command prompt and type “cd” (this will take you to the home directory. Note: even though your programming files may be located on your “D: drive”, your “.bash” files may be located on your “C: drive” ) To see the location of the home directory, type “pwd” (this will show you the home directory path and where the .bash files are probably located) To see all dot "." files in the home directory, type “ls -la” (this will show ALL files including hidden dot "." files) You will see 2 files: “.bash_profile” and “.bashrc” Open .bashrc file in VS Code Editor or your IDE and enter “source ~/.bash_profile” in first line (to point .bashrc file to .bash_profile) Open .bash_profile file in VS Code Editor and enter “alias bnode='./node_modules/.bin/babel-node'” (to create permanent bnode shortcut to execute as bash command) Save and close both files Now open the file you want to execute (index.js) and open in terminal command prompt and run file by using command “bnode index.js” Now your index.js file will execute but before creating bnode alias in .bash_profile file you would get the error "bash: bnode command not found" and it would not recognize and give errors on some ES6 code. Helpful link to learn about dotfiles: https://dotfiles.github.io/

我希望这能有所帮助!好运!

在我的.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文件,你就能识别出平台中常用的别名文件是什么。

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看起来就像这样:

来源 ~/.巴什尔克

如果你在~/中加入blah="/usr/bin/blah"。Bashrc,然后您可以在登录shell中使用$blah作为输入/usr/bin/blah的替代

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

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

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