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 ~]# 
相关推荐
电鱼智能的电小鱼3 分钟前
EFISH-SBC-RK3588 —— 厘米级定位 × 旗舰算力 × 工业级可靠‌
linux·人工智能·嵌入式硬件·边缘计算
席万里4 分钟前
Go语言企业级项目使用dlv调试
服务器·开发语言·golang
高峰君主10 分钟前
全栈自动化:从零构建智能CI/CD流水线
运维·ci/cd·自动化
yuanlaile22 分钟前
Go全栈_Golang、Gin实战、Gorm实战、Go_Socket、Redis、Elasticsearch、微服务、K8s、RabbitMQ全家桶
linux·redis·golang·k8s·rabbitmq·gin
程序员JerrySUN26 分钟前
驱动开发硬核特训 · Day 22(上篇): 电源管理体系完整梳理:I2C、Regulator、PMIC与Power-Domain框架
linux·驱动开发·嵌入式硬件
IT运维爱好者38 分钟前
Ubuntu 22.04.4操作系统初始化详细配置
linux·运维·服务器·ubuntu
樂5021 小时前
关于 Web 服务器的五个案例
linux·服务器·经验分享
用户217516114381 小时前
【linux】重定向与缓冲区
linux
一键三联啊1 小时前
【FastJSON】的parse与parseObject
linux·前端·python
离凌寒1 小时前
一、linux系统启动过程操作记录
linux