Shell 路徑擷取函式

2021-10-01 07:32:56 字數 546 閱讀 6316

basename [string / pathname] [suffix]

功能描述:

basename命令會刪掉所有的字首包括最後乙個(『/』)字元,然後將字串顯示出來。

選項:suffix為字尾,如果suffix被指定了,basename會將pathname或string中的suffix去掉。

[mubai@localhost test]$ basename /home/mubai/test.txt 

test.txt

[mubai@localhost test]$ basename /home/mubai/test.txt .txt

test

dirname [檔案絕對路徑]

功能描述:

從給定的包含絕對路徑的檔名中去除檔名(非目錄的部分),然後返回剩下的路徑(目錄的部分)。

[mubai@localhost test]$ dirname /home/mubai/test.txt 

/home/mubai

shell之檔案路徑擷取

最近寫指令碼,需要對指令碼中函式傳遞的路徑引數進行擷取,發現了以下比較好用的方法,記錄下 file dir1 dir2 dir3 my.file.txt 我們可以用 分別替換獲得不同的值 拿掉第一條 及其左邊的字串 dir1 dir2 dir3 my.file.txt 拿掉最後一條 及其左邊的字串 ...

擷取檔案路徑

開發介面時發現通過getpathname 函式得到的路徑是完全路徑,即d 測試 test.txt。如果只想得到檔名,可以用getfilename 函式來獲得,也可使用下列 inputfilepath dlg.getpathname int npos inputfilepath.reversefind...

php快速分解路徑擷取路徑

mixed parse url string url int component 1 mixed pathinfo string path int options pathinfo dirname pathinfo basename pathinfo extension pathinfo filen...