首页 > 其他 > 详细

2.5alias命令

时间:2018-03-12 15:08:46      阅读:212      评论:0      收藏:0      [点我收藏+]
2.5alias命令
命令都会有别名怎么查看呢?
which 查看命令别名和命令别名的绝对路径 有的命令有alias 有的没有

[root@localhost ~]# which ls
alias ls=‘ls --color=auto‘
/usr/bin/ls
[root@localhost ~]# which ll
alias ll=‘ls -l --color=auto‘
/usr/bin/ls
[root@localhost ~]# which man
/usr/bin/man
[root@localhost ~]# which yum
/usr/bin/yum

alias表示 命令由一个命令加选项这样的组合形成的新的命令
如果不适用ls 可以用绝对路径 区别就是 绝对路径不带颜色

[root@localhost ~]# /usr/bin/ls /
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var

/bin/ls 和 /usr/bin/ls 是一个文件做的是软连接

[root@localhost ~]# /bin/ls /usr/bin/ls
/usr/bin/ls

alias 查看所有命令别名

[root@localhost ~]# alias
alias cp=‘cp -i‘
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‘

which本身也是一个别名
PATH系统的环境变量
echo $PATH查看环境变量的内容*

[root@localhost ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

就是一系列的路径如果命令在这些文件下直接运行会生效 没在就不会生效

自定义别名 比如 laozhi=’ls -lha‘

做别名

[root@localhost ~]# alias laozhi=‘ls -lha‘

运行laozhi生效

[root@localhost ~]# laozhi
总用量 28K
dr-xr-x---. 3 root root 147 3月 12 13:58 .
dr-xr-xr-x. 18 root root 236 3月 12 13:57 ..
-rw-------. 1 root root 1.4K 1月 24 04:18 anaconda-ks.cfg
-rw-------. 1 root root 703 3月 9 21:54 .bash_history
-rw-r--r--. 1 root root 18 12月 29 2013 .bash_logout
-rw-r--r--. 1 root root 176 12月 29 2013 .bash_profile
-rw-r--r--. 1 root root 176 12月 29 2013 .bashrc
-rw-r--r--. 1 root root 100 12月 29 2013 .cshrc
drwxr-xr-x. 2 root root 6 3月 12 13:58 .ssh
-rw-r--r--. 1 root root 129 12月 29 2013 .tcshrc

which laozhi 查看

[root@localhost ~]# which laozhi
alias laozhi=‘ls -lha‘
/usr/bin/ls

取消别名

[root@localhost ~]# unalias laozhi
[root@localhost ~]# laozhi
-bash: laozhi: 未找到命令

2.5alias命令

原文:http://blog.51cto.com/13038669/2085523

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!