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

|----|--------------------|
| 参数 | 说明 |
| -p | 以可重用的格式打印所有的已定义的别名 |
[alias参数]

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.
[root@centos79-3 ~]# 
相关推荐
zmsup9 分钟前
从运维需求到产品能力:OpsArk Agent 的运维智能平台架构设计思路
运维·系统架构·agent·智能体·运维智能平台
人工智能培训13 分钟前
数字孪生驱动大模型工业知识库:为具身机器人植入领域专业经验
大数据·linux·服务器·前端·人工智能
江屿风37 分钟前
【Linux系统】【从菜鸟驿站到操作系统:一节课打通Linux重定向与缓冲区真相】流食般投喂
linux·运维·服务器·开发语言·笔记
今天要早睡_1 小时前
Linux 基础指令速查:从 ls 到 tar 的常用命令全解析
linux·运维·chrome
吴声子夜歌1 小时前
Docker入门与实战——核心概念与安装配置
运维·docker·容器
高山有多高1 小时前
【Linux笔记】UDP协议
linux
Felven11 小时前
stress-ng 与 fio 性能测试工具使用指南
linux·测试工具·fio·stress-ng
XiaoMaqqqq12 小时前
市面上正规的IP驱动产业新场景新工具哪家强
运维·python·网络协议·tcp/ip
huainingning12 小时前
RJ SW Console口忘记密码处理方法
linux·运维·服务器
布裘12 小时前
【银河麒麟】桌面系统循环登录,无法进入桌面?
linux·运维·服务器