• 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

    1. [root@centos79-3 ~]# help alias
    2. alias: alias [-p] [name[=value] ... ]
    3. Define or display aliases.
    4. Without arguments, `alias' prints the list of aliases in the reusable
    5. form `alias NAME=VALUE' on standard output.
    6. Otherwise, an alias is defined for each NAME whose VALUE is given.
    7. A trailing space in VALUE causes the next word to be checked for
    8. alias substitution when the alias is expanded.
    9. Options:
    10. -p Print all defined aliases in a reusable format
    11. Exit Status:
    12. alias returns true unless a NAME is supplied for which no alias has been
    13. defined.
    14. [root@centos79-3 ~]#

    3.2.设置临时别名

    命令:

    alias cp='echo aaaaa'

    1. [root@centos79-3 ~]# alias cp='echo aaaaa'
    2. [root@centos79-3 ~]# alias cp
    3. alias cp='echo aaaaa'
    4. [root@centos79-3 ~]#

    3.3.打印所有已定义的别名

    命令:

    alias -p

    1. [root@centos79-3 ~]# alias -p
    2. alias cp='echo aaaaa'
    3. alias egrep='egrep --color=auto'
    4. alias fgrep='fgrep --color=auto'
    5. alias grep='grep --color=auto'
    6. alias l.='ls -d .* --color=auto'
    7. alias ll='ls -l --color=auto'
    8. alias ls='ls --color=auto'
    9. alias mv='mv -i'
    10. alias rm='rm -i'
    11. alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
    12. [root@centos79-3 ~]#

    3.4.取消cp别名设置

    命令:

    unalias cp

    1. [root@centos79-3 ~]# unalias cp
    2. [root@centos79-3 ~]# alias cp
    3. -bash: alias: cp: not found

    3.5.取消所有别名设置

    命令:

    unalias -a

    备注:

    -a :取消所有命令别名

    1. [root@centos79-3 ~]# unalias -a
    2. [root@centos79-3 ~]# alias
    3. [root@centos79-3 ~]#

    3.6.unalias帮助

    命令:

    help unalias

    1. [root@centos79-3 ~]# help unalias
    2. unalias: unalias [-a] name [name ...]
    3. Remove each NAME from the list of defined aliases.
    4. Options:
    5. -a remove all alias definitions.
    6. Return success unless a NAME is not an existing alias.
    7. [root@centos79-3 ~]#

  • 相关阅读:
    Spring框架系列(11) - Spring AOP实现原理详解之Cglib代理实现
    es 初识调研,相关知识点汇总
    ML 模型监控最佳工具
    SQL教学: MySQL进阶操作详解--探索DML语句的高级用法
    【如何查看Python安装了哪些包】
    Chocolatey,Windows 上的包管理器
    PMP有没有必要续证?
    SpringBoot学习
    【随笔】提高代码学习水平(以更高的视角看事物)
    c语言的基本类型有哪些
  • 原文地址:https://blog.csdn.net/z19861216/article/details/133089279