<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          學(xué)習(xí)一個(gè) Linux 命令:realpath 命令

          共 1696字,需瀏覽 4分鐘

           ·

          2021-03-30 12:18


          轉(zhuǎn)自:戀貓大鯉魚

          鏈接:https://dablelv.blog.csdn.net/article/details/90710645

          1.命令簡(jiǎn)介

          realpath 用于獲取指定目錄或文件的絕對(duì)路徑。

          編寫 Shell 腳本中,通常會(huì)使用相對(duì)路徑來指明文件,但有時(shí)候,我們需要用到絕對(duì)路徑,此時(shí)可以使用 realpath 來獲取。

          2.命令格式

          realpath [OPTIONS] FILES

          3. 選項(xiàng)說明

          -e, --canonicalize-existing
           文件 FILE 的所有組成部件必須都存在
          -m, --canonicalize-missing
           文件 FILE 的組成部件可以不存在
          -L, --logical
           在軟鏈接之前解析父目錄 ..
          -P, --physical
           解析軟鏈接,默認(rèn)動(dòng)作
          -q, --quiet
           靜默模式輸出,禁止顯示大多數(shù)錯(cuò)誤消息
          --relative-to=DIR
           相對(duì)于目錄 DIR 的路徑
          --relative-base=DIR
           如果文件在基目錄 DIR下,打印結(jié)果會(huì)省去基目錄,否則打印絕對(duì)路徑
          -s, --strip, --no-symlinks
           不擴(kuò)展軟鏈接
          -z, --zero
           不分隔輸出,即所有的輸出均在一行而不是單獨(dú)每行
          --help
           顯示幫助信息
          --version
           顯示版本信息

          4.常用示例

          (1)打印指定文件的絕對(duì)路徑。執(zhí)行命令時(shí)當(dāng)前工作目錄為 /data/test/src。

          realpath ./hello.tgz
          /data/test/src/hello.tgz

          (2)顯示軟鏈接指向的目標(biāo)文件的絕對(duì)路徑。執(zhí)行命令時(shí)當(dāng)前工作目錄為 /data/test。

          ll
          total 4
          -rw-r--r-- 1 root root    0 Feb  1 07:26 foo
          lrwxrwxrwx 1 root root   13 Feb  1 07:05 hello.sln -> src/hello.tgz
          drwxr-xr-x 2 root root 4096 Feb  1 07:19 src

          realpath ./hello.sln
          /data/test/src/hello.tgz

          可見,即便使用相對(duì)路徑創(chuàng)建的軟鏈接,realpath 也能順利解析。

          (3)打印某個(gè)文件相對(duì)于另外一個(gè)目錄的路徑。執(zhí)行命令時(shí)當(dāng)前工作目錄為 /data/test。

          realpath --relative-to=./src ./foo
          ../foo

          (4)打印某個(gè)文件相對(duì)于基目錄的路徑,如果文件在基目錄下,則會(huì)省去基目錄。執(zhí)行命令時(shí)當(dāng)前工作目錄為 /data/test。

          realpath --relative-base=/data/test ./foo
          foo

          參考文獻(xiàn)

          [1] realpath manual

          推薦閱讀
          誤執(zhí)行了rm -fr /*之后,除了跑路還能怎么辦?!
          程序員必備58個(gè)網(wǎng)站匯總
          大幅提高生產(chǎn)力:你需要了解的十大Jupyter Lab插件

          瀏覽 44
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  国产精品内射婷婷 | 神马影院午夜福利视频 | 一区二区三区手机在线 | 天天干天天操青青草 | 好操逼网 |