linux命令 dirname


功能: 獲取給定路徑的目錄部分

 

利用man 查看dirname的說明如下:

DESCRIPTION        Output each NAME with its last non-slash component and trailing slashes removed; if NAME contains no /'s, output '.' (meaning the cur‐        rent directory).

       -z, --zero               end each output line with NUL, not newline

       --help display this help and exit

       --version               output version information and exit

 

例如:

 hbg@root:/$ dirname /usr/sbin/cron
/usr/sbin
hbg@root:/$ dirname /usr/sbin/
/usr
hbg@root:/$ dirname /usr/sbin
/usr

 

shell腳本中使用比較多的是 

cd `dirname $0`

命令。這個命令的含義是 返回這個腳本文件放置的目錄,並可以根據這個目錄來定位所要運行程序的相對位置(絕對位置除外)。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM