linux下環境變數PATH的用法

來源:互聯網
上載者:User

標籤: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的用法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.