Ubuntu 永久设置别名

版权声明:喜欢就点个赞吧,有啥疑问可以留言交流~ https://blog.csdn.net/m0_38015368/article/details/81562526

Ubuntu下永久设置别名

背景

在阿里云买了个服务器需要在本地ubuntu下远程登录,每次都需要输入一大段命令很麻烦~所以就设置一下别名让登录命令短一下吧~

具体操作

Ubuntu中别名设置文件为~/.bashrc,设置别名的样式为:

alias aliasname='command -parameter'

让我们操作一下吧。

先看一下文件内容:

cat ~/.bashrc

可以看到所有的别名设置,文件部分内容如下

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac
....中间部分省略....
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

这是Ubuntu 18中内容,可能版本不同内容不同,但这个不重要。

设置自己命名的别名

执行以下命令

vim ~/.bashrc

然后在文件末尾追加自己需要修改的别名, 我这里是添加远程连接主机的命令如下:

alias myvir='ssh [email protected].**.***'

然后保存,保存后,需要重启或者用source 命令刷新一下

刷新

执行命令

source ~/.bashrc


以上操作完后,在命令行执行

myvir

等同于执行

ssh test@39.107.**.***

猜你喜欢

转载自blog.csdn.net/m0_38015368/article/details/81562526