環境變量

環境變量

可執行文件放到環境變量裏面纔有意義web

1.
[root@web01 ~]# vim a.txt	#編輯文件,寫入命令
ls -l
[root@web01 ~]# ll
total 16
-rw-------. 1 root root 1444 May  8 04:01 anaconda-ks.cfg  
-rw-r--r--  1 root root   10 May 11 21:46 a.txt  # 沒有執行權限,可是root能夠執行
[root@web01 ~]# sh a.txt 	#a.txt實際上就是一個腳本
total 16
-rw-------. 1 root root 1444 May  8 04:01 anaconda-ks.cfg
-rw-r--r--  1 root root   10 May 11 21:46 a.txt

2.
[root@web01 ~]# vim web02
ssh root@172.16.1.8 >/dev/null
[root@web01 ~]# sh web02	
#該文件沒有添加執行權限,因此只能 sh web02來執行(在別的目錄下須要用絕對路徑來執行)
Last login: Mon May 11 21:52:29 2020 from 172.16.1.7
[root@web02 ~]# 	
#登陸成功,第一次執行要輸入yes和密碼,第二次直接輸入密碼

3.
#本身作了一個命令,達到指定的目的
[root@web01 ~]# vim web02
ssh root@172.16.1.8 >/dev/null
[root@web01 ~]# chmod u+x web02 
[root@web01 ~]# ll
total 20
-rw-------. 1 root root 1444 May  8 04:01 anaconda-ks.cfg
-rwxr--r--  1 root root   20 May 11 21:51 web02		#添加了執行權限,能夠直接執行
[root@web01 ~]# mv web02 /usr/bin/	#移到環境變量 目錄下,或者將改文件所在目錄加入到環境變量,能夠直接執行 和TAB
[root@web01 ~]# we
weak-modules  web02         
[root@web01 ~]# web02 
Last login: Mon May 11 21:54:10 2020 from 172.16.1.7
[root@web02 ~]#			#執行成功
相關文章
相關標籤/搜索