Nội dung

Dùng Alias trong terminal, giúp cuộc đời dễ dàng hơn

Nội dung

Bạn đã từng bao giờ phải gõ lặp đi lặp lại rất nhiều trong terminal chỉ để thực hiện một việc gì đó ví dụ như lệnh git status, git add ., yarn start hay là ssh [email protected]… Và khi đó thì để tăng năng suất làm việc thì bạn nên sử dụng alias trong terminal để giúp cho mỗi lần thay vì phải gõ một lệnh dài thì bạn chỉ cần gõ lệnh alias đã thiết lập trước là ok rùi.

Để thiết lập xài được alias thì ta phải quy định trong file ~/.bashrc [rc viết tắt của run command] trong hệ điều hành linux-ubuntu. Và nếu bạn xài zsh thì bạn sẽ lưu alias trong ~/.zshrc. Cú pháp để thiết lập cũng đơn giản với cấu trúc là alias <tên_viết_tắt>='<câu lệnh thực thi + tham số (nếu có)>'. Ví dụ alias e='exit' thì tại terminal khi bạn muốn thoát khỏi terminal tắt nó đi, thì thay vì gõ exit và Enter thì bạn gõ e rồi Enter là sẽ exit.

Ví dụ cụ thể những lệnh alias của mình cho mọi người tham khảo bên dưới nhé. Nhớ bấm nút code để mở rộng xem toàn bộ alias để chọn ra những alias hữu ích nhé.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
alias mv='mv -i'
alias cp='cp -i'
alias ln='ln -i'
alias reboot='sudo /sbin/reboot'
alias shutdown='sudo /sbin/shutdown'
alias update='sudo apt update'
alias upgrade='sudo apt upgrade -y'
alias aconfig='nvim ~/.config/alacritty/alacritty.yml'
alias nvimconfig='nvim ~/.config/nvim/init.vim'
alias android=" ~/Downloads/android-studio/bin/studio.sh"
alias googledrive='XDG_CURRENT_DESKTOP=GNOME gnome-control-center'
alias xampp='sudo /opt/lampp/manager-linux-x64.run'
alias postman='~/Postman/app/Postman'
alias system='inxi -Fxz'
alias vim='nvim'
alias dev='yarn dev'
alias gs='git status'
alias gb='git branch'
alias gr='git remote -v'
alias ga='git add .'
alias gc='git commit --no-verify -m'
alias gca='git commit --no-verify --amend -m'
alias gp='git push origin'
alias gpf='git push -f origin'
alias gco='git checkout'
alias gcm='git checkout master && git pull origin master'
alias gl='git log --oneline --graph'
alias bashrc='nvim ~/.bashrc'
alias dev5='DEV_PORT=5000 yarn dev'
alias in='sudo apt install -y'
alias e='exit'
alias au='sudo apt autoremove'
## tmux
alias tmuxc='nvim ~/.tmux.conf'
alias ts='tmux new -s'
alias tr='tmux a -t'
alias tls='tmux ls'
## /tmux
alias picomstart='/home/sen/.config/picom/autoblurpicom.sh'
alias picomc='nvim ~/.config/picom/picom.conf'
# remapping CAPSLOCK to ESCAPE
alias esc='xmodmap -e "clear Lock" -e "keysym Caps_Lock = Escape"'
alias f='find . |grep '
alias c='clear'
alias h='history|grep'
## exit
alias :q='exit'
# helper
alias zshr='source ~/.zshrc && clear'
alias tmuxr='tmux source-file ~/.tmux.conf'