linux - bash 硬链接(hard link)不起作用

标签 linux bash hardlink

我想将一个目录硬链接(hard link)到另一个目录,但这个脚本不起作用。由于某种奇怪的原因,它硬链接(hard link)到所有目录。因此“电视节目目录”被硬链接(hard link)到“moviesdestpath”、“tvdestdestpath”和“miscdestpath”

有什么想法吗?

#!/bin/bash
tvdestpath="/rpn-san/downloads/complete/torrents/tvshows-ready/$2"
moviedestpath="/rpn-san/downloads/complete/torrents/movies-ready/$2"
miscdestpath="/rpn-san/downloads/complete/torrents/misc-ready/$2"
torrentid="$1"
torrentname="$2"
torrentpath="$3"
torrentdir="$torrentpath/$torrentname"

#hardlink to "tvshows-ready"
cp -al "$torrentdir" "$tvdestpath/"
sleep 5
cp -al "$torrentdir" "$moviesdestpath/"
sleep 5
cp -al "$torrentdir" "$miscdestpath/"

最佳答案

一切都明白了,我是个白痴。我实际上是在不应该的情况下复制到所有目录。

#!/bin/bash
tvdestpath="/rpn-san/downloads/complete/torrents/tvshows-ready/$2"
moviedestpath="/rpn-san/downloads/complete/torrents/movies-ready/$2"
miscdestpath="/rpn-san/downloads/complete/torrents/misc-ready/$2"
torrentid="$1"
torrentname="$2"
torrentpath="$3"
torrentdir="$torrentpath/$torrentname"

#hardlink to "tvshows-ready"
if [ "$torrentpath" == "/rpn-san/downloads/complete/torrents/tvshows" ]; then
cp -al "$torrentdir" "$tvdestpath/"
fi

sleep 5
#hardlink to "movies-ready"
if [ "$torrentpath" == "/rpn-san/downloads/complete/torrents/movies" ]; then
cp -al "$torrentdir" "$moviedestpath/"
fi

sleep 5
#hardlink to "misc-ready"
if [ "$torrentpath" == "/rpn-san/downloads/complete/torrents/misc" ]; then
cp -al "$torrentdir" "$miscdestpath/"
fi

关于linux - bash 硬链接(hard link)不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43967104/

相关文章:

c++ - 我可以访问 Unity 背景元素吗?

Bash:是否可以通过评估命令为单个子进程设置环境变量?

linux - 为什么一旦父 bash 脚本死亡,来自 bash 的 eval 调用的 child 就会成为孤儿?

linux - 在 unix 上创建标记文件的最便宜的方法

linux - 如何列出符号链接(symbolic link)未引用的所有文件

linux - 如何获取expect访问的ssh命令的返回值?

linux - 如何在 if 条件中使用 expr

bash - 在 Yosemite 中设置环境变量

php - 用PHP编辑硬链接(hard link)或软链接(soft link)的目标位置内容

unix - 我们可以在 UNIX 中创建指向符号链接(symbolic link)的硬链接(hard link)吗?