【问题标题】:Get the path after "n" directory in the whole path获取全路径中“n”目录后的路径
【发布时间】:2014-04-09 19:17:22
【问题描述】:

我想剪切这条路径以获得第“n”个目录之后的剩余路径

原始路径

/home/user/path/to/something/useful

在 bash 中,如果我传入 2,它应该给我

/path/to/something/useful

如果我使用 3,它会给我

/to/something/useful

我需要这个使用 bash。我知道 pwd 给了我当前的导演,cut -d/ -f4 <<<"$PWD" 给了我第三个目录 但不知道之后如何获得剩余的路径。

【问题讨论】:

    标签: bash shell path terminal directory


    【解决方案1】:

    - 添加到-f4 以获取第四个字段以及之后的所有内容。

    cut -d/ -f4- <<< "$PWD"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-05
      • 2010-09-27
      • 2023-03-02
      • 2017-03-05
      • 1970-01-01
      • 2015-02-01
      • 1970-01-01
      相关资源
      最近更新 更多