echo $PATH
可以查看系统的环境变量PATH的值,使用which命令可以查看某个命令所在的绝对路径;[root@localhost ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@localhost ~]# whereis ls
ls: /bin/ls /usr/share/man/man1/ls.1.gz
[root@localhost ~]# which cat
/bin/cat
执行命令PATH=$PATH:/tmp 可以把/tmp目录加到PATH里面
这样我们可以使用/tmp/下面的可执行文件作为命令让PATH永久生效的,需要把它加入到/etc/profile 最后一行里,重启生效,或者直接运行命令生效: source /etc/profile = . /etc/profile
[root@localhost ~]# PATH=$PATH:/tmp
[root@localhost ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/tmp/
[root@localhost ~]# cp /bin/cat /tmp/yong
[root@localhost ~]# ls /tmp/
yong yum.log
[root@localhost ~]# yong /tmp/passwd | head -1
root:x:0:0:root:/root:/bin/bash
#加入PATH后/tmp下面的命令可以直接运行。yong相当于cat
关于alias别名
查询别名,只在当前窗口生效。
[root@localhost /]# alias
alias cp='cp -i'
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'
自定义alias别名
[root@localhost /]# alias aming='ls /tmp/'
[root@localhost /]# aming
yum.log
[root@localhost /]# ls /tmp/
yum.log
alias设置命令的别名,例如 alias aming='ls -lt' 只是临时使用,重启不存在。
解除别名使用 unalias aming 让别名永久生效,需要把设置别名的命令,加入到 /root/.bashrc 里[root@localhost ~]# cat /root/.bashrc
# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias yo='ls -l'
yo=‘ls -l' 这一条为新增的;
[root@localhost~]#source /root/.bashrc
#别名生效需要执行此命令,等同于. /root/.bashrc ,或者重启后生效。
[root@localhost ~]# yo
total 24
-rw-------. 1 root root 1090 Nov 13 09:29 anaconda-ks.cfg
-rw-r--r--. 1 root root 9119 Nov 13 09:29 install.log
-rw-r--r--. 1 root root 3091 Nov 13 09:28 install.log.syslog
yo别名生效,yo=ls -l 命令;
查看用户家目录的命令 ehco $HOME
[root@localhost tmp]# echo $HOME
/root