• 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 ~]#

  • 相关阅读:
    Gin + Element + 云IDE 挑战一小时打造春联生成平台
    线程三连鞭之“线程基础”
    云平台功能:应用回收站的诞生与使用说明
    数据结构题目收录(二十五)
    新库上线 | CnOpenData科学研究和技术服务商注册企业基本信息数据
    React/Vue项目-请求文件封装(Axios,WebSocket)
    第一讲 递归和递推
    MMDeploy快速安装及使用说明
    多目标应用:基于多目标粒子群优化算法MOPSO求解微电网多目标优化调度(MATLAB代码)
    代码随想录day58|739. 每日温度496. 下一个更大元素 I
  • 原文地址:https://blog.csdn.net/z19861216/article/details/133089279