Linux命令(95)之alias

简介: Linux命令(95)之alias

linux命令之alias

1.alias介绍
linux命令alias是用来将/bin目录下的命令进行别名设置,将一些较长的命令进行简化。

alias命令的作用只局限于该次登入的操作,相当于临时变量。

如果对当前用户永久生效,需修改~/.bashrc文件,使用命令source .bashrc生效。

如果对全局用户生效,需修改/etc/profile或/etc/bashrc文件,使用命令source /etc/profile或source /etc/bashrc生效。

2.alias用法
alias [参数] key=value

alias参数
参数 说明
-p 以可重用的格式打印所有的已定义的别名
3.实例
3.1.alias帮助
命令:

help alias

[root@centos79-3 ~]# help alias
alias: alias [-p] [name[=value] ... ]
Define or display aliases.

Without arguments, `alias' prints the list of aliases in the reusable
form `alias NAME=VALUE' on standard output.

Otherwise, an alias is defined for each NAME whose VALUE is given.
A trailing space in VALUE causes the next word to be checked for
alias substitution when the alias is expanded.

Options:
  -p    Print all defined aliases in a reusable format

Exit Status:
alias returns true unless a NAME is supplied for which no alias has been
defined.

[root@centos79-3 ~]#

3.2.设置临时别名
命令:

alias cp='echo aaaaa'

[root@centos79-3 ~]# alias cp='echo aaaaa'
[root@centos79-3 ~]# alias cp
alias cp='echo aaaaa'
[root@centos79-3 ~]#
3.3.打印所有已定义的别名
命令:

alias -p

[root@centos79-3 ~]# alias -p
alias cp='echo aaaaa'
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 which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[root@centos79-3 ~]#
3.4.取消cp别名设置
命令:

unalias cp

[root@centos79-3 ~]# unalias cp
[root@centos79-3 ~]# alias cp
-bash: alias: cp: not found
3.5.取消所有别名设置
命令:

unalias -a

备注:

-a :取消所有命令别名

[root@centos79-3 ~]# unalias -a
[root@centos79-3 ~]# alias
[root@centos79-3 ~]#
3.6.unalias帮助
命令:

help unalias

[root@centos79-3 ~]# help unalias
unalias: unalias [-a] name [name ...]
Remove each NAME from the list of defined aliases.

Options:
  -a    remove all alias definitions.

Return success unless a NAME is not an existing alias.

————————————————
版权声明:本文为CSDN博主「小黑要上天」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/z19861216/article/details/133089279

目录
相关文章
|
3天前
|
Linux
Linux的cp命令如何使用?
Linux的cp命令如何使用?
11 5
|
7天前
|
Linux
Linux常用命令包括
Linux常用命令包括
16 5
|
7天前
|
Linux
Linux命令
Linux命令
18 5
|
3天前
|
安全 Linux Shell
常见的 Linux 命令大全(表格形式)
常见的 Linux 命令大全(表格形式)
|
11天前
|
Linux Python Perl
Linux命令删除文件里的字符串
Linux命令删除文件里的字符串
26 7
|
11天前
|
Shell Linux
Linux shell编程学习笔记82:w命令——一览无余
Linux shell编程学习笔记82:w命令——一览无余
|
13天前
|
Linux Perl
Linux之sed命令
Linux之sed命令
|
13天前
|
Linux
深入理解Linux中的cp命令:文件与目录的复制利器
深入理解Linux中的cp命令:文件与目录的复制利器
|
13天前
|
Linux Docker 容器
9. 同步执行Linux多条命令
9. 同步执行Linux多条命令
|
13天前
|
Linux Shell
10-10|linux命令查询 关键字在文本中出现的行数
10-10|linux命令查询 关键字在文本中出现的行数