0%

有用的 bash alias

*Photo by Sai Kiran Anagani on Unsplash

当新建用户时,在自己的 home 目录应该有如下几个文件:.bash_profile .bashrc .bash_logout,有可能有两个,也有可能都没有,这个时候需要自己新建,在 .bash_profile 文件中可以写入以下内容,这样在每次登录都会执行 .bashrc 了,不然你写了一堆 alias 可能登录一看根本没用。

1
2
3
4
5
6
7
# .bash_profile
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi

可以将下面的 alias 写入 .bashrc 也可以写入 .bash_aliases,因为如果 .bashrc 是自动生成的话,它会执行 .bash_aliases,当然嫌麻烦直接堆在 .bashrc 算了

可能会有换行的问题,用 vim 打开,输入 set ff=unix 命令就行了

Change Directories

  • alias ..=’cd ..’

  • alias …=’cd ../..’

  • alias ….=’cd ../../..’

  • alias …..=’cd ../../../..’

  • alias ……=’cd ../../../../..’

  • alias 2=’cd ..’

  • alias 3=’cd ../..’

  • alias 4=’cd ../../..’

  • alias 5=’cd ../../../..’

  • alias 6=’cd ../../../../..’

Git commands

  • alias gs=’git status’
  • alias gl=’git log –pretty=format:”%C(auto)%h %Cred%an(%ad) %C(auto)%s%d” –graph –date=short’

History commands

  • alias h=’history’
  • alias h1=’history 10’
  • alias h2=’history 20’
  • alias h3=’history 30’

List commands

  • alias l.=’ls -d .* –color=auto’
  • alias ls=’ls –color=auto’
  • alias ll=’ls -la’
  • alias l=ll

Install & Update utilties

  • alias sai=’sudo apt install ‘
  • alias sai=’sudo apt-get install ‘
  • alias sau=’sudo apt update’
  • alias sau=’sudo apt-get update’
  • alias update=’sudo apt update’

Get details of a process

  • alias paux=’ps aux | grep ‘

Welcome to my other publishing channels