標籤:linux 環境變數 centos path
echo $PATH
可以查看系統的環境變數PATH的值,使用which命令可以查看某個命令所在的絕對路徑;
[[email protected] ~]# echo $PATH/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin[[email protected] ~]# whereis lsls: /bin/ls /usr/share/man/man1/ls.1.gz[[email protected] ~]# which cat/bin/cat
執行命令 PATH=$PATH:/tmp 可以把/tmp目錄加到PATH裡面
這樣我們可以使用/tmp/下面的可執行檔作為命令
讓PATH永久生效的,需要把它加入到/etc/profile 最後一行裡,重啟生效,或者直接運行命令生效:
source /etc/profile = . /etc/profile
[[email protected] ~]# PATH=$PATH:/tmp[[email protected] ~]# echo $PATH/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/tmp/[[email protected] ~]# cp /bin/cat /tmp/yong[[email protected] ~]# ls /tmp/ yong yum.log[[email protected] ~]# yong /tmp/passwd | head -1 root:x:0:0:root:/root:/bin/bash
#加入PATH後/tmp下面的命令可以直接運行。yong相當於cat
關於alias別名
查詢別名,只在當前視窗生效。
[[email protected] /]# 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別名
[[email protected] /]# alias aming=‘ls /tmp/‘[[email protected] /]# amingyum.log[[email protected] /]# ls /tmp/yum.log
alias設定命令的別名,例如 alias aming=‘ls -lt‘ 只是臨時使用,重啟不存在。
解除別名使用 unalias aming
讓別名永久生效,需要把設定別名的命令,加入到 /root/.bashrc 裡
[[email protected] ~]# cat /root/.bashrc # .bashrc# User specific aliases and functionsalias rm=‘rm -i‘alias cp=‘cp -i‘alias mv=‘mv -i‘alias yo=‘ls -l‘
yo=‘ls -l‘ 這一條為新增的;
[[email protected] ~]# source /root/.bashrc
#別名生效需要執行此命令,等同於. /root/.bashrc ,或者重啟後生效。
[[email protected] ~]# 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
[[email protected] tmp]# echo $HOME/root
本文出自 “模範生的學習部落格” 部落格,請務必保留此出處http://8802265.blog.51cto.com/8792265/1622606
linux下環境變數PATH的用法