Bash 별칭을 어떻게 만듭니 까?
OSX를 사용 중이며 alias blah="/usr/bin/blah"
구성 파일에 이와 같은 것을 넣어야 하지만 구성 파일의 위치를 모르겠습니다.
당신은 추가 할 수 있습니다 alias
또는를 function
시동 스크립트 파일에서. 보통이다 .bashrc
, .bash_login
또는 .profile
홈 디렉토리에 파일.
이러한 파일은 숨겨져 있기 때문에 파일 ls -a
을 나열해야합니다. 없는 경우 만들 수 있습니다.
정확하게 기억한다면, Mac을 구입했을 때 .bash_login
파일이 없었습니다. 내가 넣을 수 있도록 자신을 위해 그것을 만들 수 있었다 prompt info
, alias
, functions
그것에서 등.
생성하려는 단계는 다음과 같습니다.
- 터미널 시작
cd ~/
홈 폴더로 이동하려면 입력touch .bash_profile
새 파일을 작성하려면 입력 하십시오..bash_profile
자주 사용하는 편집기로 편집 하십시오 (또는open -e .bash_profile
텍스트 편집기에서 입력 하여 열 수 있습니다) .- 입력
. .bash_profile
다시로드.bash_profile
하고 추가 별칭을 업데이트합니다.
OS X에서는 ~ / .bash_profile을 사용하려고합니다. 기본적으로 Terminal.app는 각각의 새 창마다 로그인 쉘을 열기 때문입니다.
다른 구성 파일 및 사용 시점에 대한 자세한 내용은 다음을 참조하십시오. .bashrc, .bash_profile 및 .environment의 차이점은 무엇입니까?
그리고 OSX와 관련하여 여기 : .bash_profile, .bashrc에 대해, 그리고 별칭은 어디에 작성해야합니까?
난 그냥 숭고한 zshrc를 열고 편집합니다.
subl .zshrc
그리고 이것을 숭고한 곳에 추가하십시오 :
alias blah="/usr/bin/blah"
이것을 터미널에서 실행하십시오 :
source ~/.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
파일 을 열면 플랫폼에서 별칭에 일반적으로 사용되는 파일을 식별 할 수 있다고 생각합니다 .
cd /etc
sudo vi bashrc
다음과 같이 추가하십시오 :
alias ll="ls -lrt"
마지막으로 터미널을 다시 시작하십시오.
스크립트 및 프로그램 ~/.bashrc
의 구성 파일은 터미널을 사용할 때로드되는 구성 파일입니다 ~/.bash_login
.
가장 좋은 방법은에 모든 것을 넣는 것입니다 ~/.bashrc
.
특정 질문에 대해서는 다음을 입력하십시오 (기존 ~ / .bashrc를 덮어 씁니다).
echo "alias blah=\"/usr/bin/blah\"" >>~/.bashrc
터미널로 들어가면 ~/.bashrc
새 별칭 으로 파일이 생성됩니다. 그런 다음 파일을 편집하여 새 별칭, 기능, 설정 등을 추가하십시오.
- 집으로 이동
- .bashrc 열기
파일 맨 아래에 별명 작성
alias alias_name='command to do' eg: alias cdDesktop='cd /Desktop'
파일을 저장하십시오
소스 .bashrc
source ~/.bashrc
터미널을 열고 (Ctrl + Alt + T) cdDesktop을 입력하고 Enter 키를 누릅니다
macOS Majave에서 작동합니다.
몇 가지 간단한 단계를 수행 할 수 있습니다.
1) 열린 터미널
2) sudo nano /.bash_profile
3) 예를 들어 별명을 추가하십시오.
# 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"
4) source /.bash_profile
끝난. 사용하고 즐기십시오!
당신이 두는 경우에 blah="/usr/bin/blah"
당신에 ~/.bashrc
당신은 사용할 수있는 $blah
입력 대용으로 로그인 쉘에/usr/bin/blah
.bashrc
홈 디렉토리에서 파일 을 편집하고 싶을 것입니다 .
맥 OS 카탈리나 이상
애플은 단지 전환 에 기본 쉘을 zsh을 설정 파일이 포함되도록 ~/.zshenv
하고 ~/.zshrc
. 이것은 ~/.bashrc
zsh 와 같습니다 . 파일을 편집하고 필요한 것을 추가하십시오. 새 터미널 창을 열 때마다 소스가 제공되어야합니다.
nano ~/.zshenv
alias py=python
그런 다음 ctrl + x, y를 입력 한 다음 입력하여 저장하십시오.
This file seems to be executed no matter what (login, non-login, or script), so seems better than the ~/.zshrc
file.
High Sierra and earlier
The default shell is bash, and you can edit the file ~/.bash_profile
and add aliases:
nano ~/.bash_profile
alias py=python
Then ctrl+x, y, and enter to save. See this post for more on these configs. It's a little better to set it up with your alias in ~/.bashrc
, then source ~/.bashrc
from ~/.bash_profile
. In ~/.bash_profile
it would then look like:
source ~/.bashrc
To create permanent alias shortcut, put it in .bash_profile file and point .bashrc file to .bash_profile file. Follow these steps (I am creating an alias command called bnode to run babel transpiler on ES6 code):
- Go to terminal command prompt and type “cd” (this will take you to 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 location of 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 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/
Hope this helps! Good luck!
I think it's proper way:
1) Go to teminal. open ~/.bashrc
. Add if not exists
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
2) open ~/.bash_aliases
. If not exists: touch ~/.bash_aliases && open ~/.bash_aliases
3) To add new alias rather
- edit .bash_aliases
file and restart terminal or print source ~/.bash_aliases
- print echo "alias clr='clear'" >> ~/.bash_aliases && source ~/.bash_aliases
where your alias is alias clr='clear'
.
4) Add line source ~/.bash_aliases
to ~/.bash_profile
file. It needs to load aliases in each init of terminal.
create a bash_profile at your user root - ex
/user/username/.bash_profile
open file
vim ~/.bash_profile
add alias as ex. (save and exit)
alias mydir="cd ~/Documents/dirname/anotherdir"
in new terminal just type mydir - it should open
/user/username/Documents/dirname/anotherdir
참고URL : https://stackoverflow.com/questions/8967843/how-do-i-create-a-bash-alias
'Programing' 카테고리의 다른 글
Ruby on Rails 3 양식의 _snowman 매개 변수는 무엇입니까? (0) | 2020.05.24 |
---|---|
Visual Studio에서 결과 찾기를 클릭하면 잘못된 창에서 코드가 열립니다. (0) | 2020.05.24 |
항상 부호를 표시하는 사용자 정의 숫자 형식 문자열 (0) | 2020.05.24 |
쿠키가 만료되지 않도록 설정 (0) | 2020.05.24 |
localhost에서 페이스 북 개발 (0) | 2020.05.24 |