【问题标题】:Bash: the first path then the second as relative path to the first path in the same commandBash:第一个路径,然后是第二个作为同一命令中第一个路径的相对路径
【发布时间】:2018-12-01 16:28:28
【问题描述】:

假设我想要:ln -s /very/long/path/to_file /very/long/path/from_file

有没有办法不再次输入 from_file 的完整路径?

喜欢:ln -s /very/long/path/to_file [sign]/from_file

sign 自动显示为/very/long/path

你知道一些 bash、zsh 或 fish 的方法吗?

【问题讨论】:

  • 虽然@faho 回答了您的具体问题,但我想指出您的符号链接不必要地低效。遍历它会导致内核遍历/very/long/path 两次。您应该使用相对符号链接:ln -s to_file /very/long/path/from_file

标签: bash zsh fish


【解决方案1】:

大括号展开!

ln -s /very/long/path/{to_file,from_file}

【讨论】:

    【解决方案2】:

    是的,当然你可以像这样存储在一个变量中:

    variable=/very/long/path
    

    然后像这样使用它:

    ln -s $variable/to_file $variable/from_file
    

    【讨论】:

    • 当然我不是指任何预先准备好的变量。我正在寻找“符号”,它会自动显示为第一个参数/路径中定义的第二个参数的当前相对路径。
    • 如果您需要重复使用该/very/long/path,则需要将其存储在某个地方。
    • 如果您需要重复使用该/very/long/path,则需要将其存储在某个地方。
    【解决方案3】:

    好吧,如果使用 Bash,剪切(前一个单词,ctrl-w)并粘贴(ctrl-y) 是你的朋友:

    $ ln -s /very/long/path/ ctrl-w ctrl-yto_file 空格ctrl-yfrom_file

    如果路径中有空格,则需要ctrl-w多。

    【讨论】:

    • zsh 和 fish shell 有更好的方法吗?
    • 不知道,我不使用它们。
    猜你喜欢
    • 2023-04-08
    • 2020-11-13
    • 1970-01-01
    • 1970-01-01
    • 2016-01-15
    • 1970-01-01
    • 2012-09-27
    • 2021-04-16
    • 2014-01-29
    相关资源
    最近更新 更多