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 ~]# 
相关推荐
易保山5 分钟前
MIT6.S081 - Lab6 Copy-on-Write(写时复制)
linux·操作系统·c
獨枭25 分钟前
Linux 下安装和使用 Jupyter Notebook
linux·chrome·jupyter
Monee..35 分钟前
linux里安装pip和conda
linux·conda·pip
阳区欠1 小时前
【Linux】进程通信
linux·运维·服务器·共享内存·进程通信·system v·管道文件
may_一一1 小时前
终端SSH连接工具SecureCRT安装和连接Linux
运维·服务器·ssh
姓刘的哦2 小时前
Ubuntu环境安装
linux·运维·ubuntu
厦门德仔2 小时前
【C#】C#字符串拼接的6种方式及其性能分析对比
服务器·windows·c#
春生黎至10053 小时前
GZ073网络系统管理赛项赛题第1套模块A:网络构建解题笔记
运维·网络
IT程序媛-桃子3 小时前
【网安面经合集】42 道高频 Web 安全面试题全解析(附原理+防御+思路)
运维·网络·安全·面试
❀͜͡傀儡师3 小时前
多台服务器上docker部署 Redis 集群
运维·服务器·redis