我在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/
我希望这能有所帮助!好运!
其他回答
cd /etc
sudo vi bashrc
添加如下内容:
alias ll="ls -lrt"
最后重启终端。
脚本和程序的配置文件是~/。bashrc和使用Terminal时加载的配置文件是~/.bash_login。
我认为最好的方法是把所有东西都放在~/.bashrc中。
对于您的特定问题,只需输入(这将覆盖任何现有的~/.bashrc):
echo "alias blah=\"/usr/bin/blah\"" >>~/.bashrc
输入终端和~/。Bashrc文件将与您的新别名一起创建。之后,只需编辑文件,添加新的别名,函数,设置等。
如果你在~/中加入blah="/usr/bin/blah"。Bashrc,然后您可以在登录shell中使用$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
要创建永久别名快捷方式,请将其放在.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/
我希望这能有所帮助!好运!
推荐文章
- 在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