alias的用法

为啥使用alias?

alias命令用来设置指令的别名。我们可以使用该命令可以将一些较长的命令进行简化。使用alias时,用户必须使用单引号”将原来的命令引起来,防止特殊字符导致错误

 

怎么使用alias?

语法

alias(选项)(参数)

选项

-p:打印已经设置的命令别名。

参数

命令别名设置:定义命令别名,格式为“命令别名=‘实际命令’”。

实例

alias 的基本使用方法为:

alias 新的命令='原命令 -选项/参数'

例如:alias l=‘ls-lsh’将重新定义ls命令,现在只需输入l就可以列目录了。直接输入 alias 命令会列出当前系统中所有已经定义的命令别名。

要删除一个别名,可以使用unalias命令,如 unalias l

查看当前系统的alias

[root@localhost /]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias teddy='mysql -uroot -p123456'
alias tim='du -h --max-depth=1'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

 

使其永久生效的方法:

定义一个文件 /etc/profile.d/alias.sh (alias.sh文件名是任意取的),然后通过 #source /etc/profile.d/alias.sh使其生效。

通过这个方法,就可以使自己(自定义)的别名永久生效了。


参考:https://wangchujiang.com/linux-command/c/alias.html

alias的用法
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Scroll to top
0
Would love your thoughts, please comment.x
()
x