我在OSX上,我需要把这样的东西,别名blah=“/usr/bin/blah”在配置文件中,但我不知道配置文件在哪里。
当前回答
在OS X上,你需要使用~/.bash_profile。这是因为默认终端。应用程序为每个新窗口打开一个登录shell。
查看更多关于不同的配置文件以及何时使用它们的信息: .bashrc, .bash_profile和.environment之间有什么区别?
和在OSX这里:关于.bash_profile, .bashrc,别名应该写在哪里?
其他回答
在我的.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文件,你就能识别出平台中常用的别名文件是什么。
在OS X上,你需要使用~/.bash_profile。这是因为默认终端。应用程序为每个新窗口打开一个登录shell。
查看更多关于不同的配置文件以及何时使用它们的信息: .bashrc, .bash_profile和.environment之间有什么区别?
和在OSX这里:关于.bash_profile, .bashrc,别名应该写在哪里?
您可能希望在主目录中编辑.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
macOS Catalina用户:
步骤1:创建或更新.zshrc文件
vi ~/.zshrc
步骤2:添加别名行
alias blah="/usr/bin/blah"
步骤3:源.zshrc
source ~/.zshrc
步骤4:通过在命令提示符上输入alias来检查您的别名
alias
推荐文章
- 在Bash中模拟do-while循环
- 在Bash中将输出赋给变量
- 在OSX 10.11中安装Scrapy时,“OSError: [Errno 1]操作不允许”(El Capitan)(系统完整性保护)
- 如何在Mac OS X 10.6中使硬件发出哔哔声
- 从Cocoa应用程序执行一个终端命令
- Android Studio无法找到有效的Jvm(与MAC OS相关)
- 从Docker容器获取环境变量
- NSRange从Swift Range?
- 如何重定向标准derr和标准输出到不同的文件在同一行脚本?
- 如何在交互式Python中查看整个命令历史?
- 如何循环通过一个目录递归删除具有某些扩展名的文件
- 在Bash中获取日期(比当前时间早一天)
- Linux: kill后台任务
- 在OSX中永久设置PATH环境变量
- 如何停止mysqld