我在OSX上,我需要把这样的东西,别名blah=“/usr/bin/blah”在配置文件中,但我不知道配置文件在哪里。
当前回答
它适用于我的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
完成了。使用并享受!
其他回答
要创建永久别名快捷方式,请将其放在.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
在root - ex用户下创建bash_profile
/user/username/.bash_profile
打开的文件
vim ~ / . bash_profile
添加别名为ex.(保存并退出)
alias mydir="cd ~/Documents/dirname/anotherdir"
在新终端中输入mydir -它应该会打开
/user/username/Documents/dirname/anotherdir
回家吧 打开. bashrc 在文件底部创建别名 别名alias_name='要做的命令' 例如:alias cdDesktop='cd /Desktop' 保存文件 源. bashrc 源~ / . bashrc 打开终端(Ctrl+Alt+T),输入cdDesktop并按enter
在OS X上,你需要使用~/.bash_profile。这是因为默认终端。应用程序为每个新窗口打开一个登录shell。
查看更多关于不同的配置文件以及何时使用它们的信息: .bashrc, .bash_profile和.environment之间有什么区别?
和在OSX这里:关于.bash_profile, .bashrc,别名应该写在哪里?