我在OSX上,我需要把这样的东西,别名blah=“/usr/bin/blah”在配置文件中,但我不知道配置文件在哪里。
当前回答
要创建永久别名快捷方式,请将其放在.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/
我希望这能有所帮助!好运!
其他回答
我需要运行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、.bash_login或.profile文件。
由于这些文件是隐藏的,您必须执行ls -a命令来列出它们。如果你没有,你可以创建一个。
如果我没记错的话,当我买了我的Mac时,.bash_login文件并不在那里。我必须为自己创建它,这样我就可以把提示信息、别名、函数等放在里面。
如果你想创建一个,以下是步骤:
启动终端 输入cd ~/进入主文件夹 输入touch .bash_profile创建新文件。 使用您喜欢的编辑器编辑.bash_profile(或者您可以键入open -e .bash_profile在TextEdit中打开它。 输入. .bash_profile重新加载.bash_profile并更新您添加的任何别名。
cd /etc
sudo vi bashrc
添加如下内容:
alias ll="ls -lrt"
最后重启终端。
要创建永久别名快捷方式,请将其放在.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和使用Terminal时加载的配置文件是~/.bash_login。
我认为最好的方法是把所有东西都放在~/.bashrc中。
对于您的特定问题,只需输入(这将覆盖任何现有的~/.bashrc):
echo "alias blah=\"/usr/bin/blah\"" >>~/.bashrc
输入终端和~/。Bashrc文件将与您的新别名一起创建。之后,只需编辑文件,添加新的别名,函数,设置等。
推荐文章
- bash:错误的替换
- 如何在bash中删除字符后的所有文本?
- 如何配置git bash命令行补全?
- Shell脚本:在Shell脚本中执行python程序
- /bin/sh: apt-get:未找到
- 在Mac上安装R -警告消息:设置LC_CTYPE失败,使用“C”
- 如何检索给定相对的绝对路径
- 如何在shell管道中使用“jq”?
- 如何使用jq从JSON获得键名
- 图形化对?
- 我如何能匹配一个字符串与正则表达式在Bash?
- 为什么cURL返回错误“(23)Failed writing body”?
- 节点和错误:EMFILE,打开的文件太多
- 在Unix shell中计算一列数字
- 如何使用命令行工具为Mac OS X创建一个漂亮的DMG ?