我想将目录硬链接到其他目录,但是此脚本不起作用。由于某种奇怪的原因,它硬链接到所有目录。因此“电视节目目录”会被硬链接到“ 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/