RSYNC:是否同步文本文件上文件夹列表中的所有文件



作为我正在编写的文件管理脚本的一部分,我想使用rsync读取文本文件上文件夹的POSIX路径列表。然后我希望它将所有这些文件夹及其内容移动到另一个位置。我尝试了以下方法:

rsync -avPh --no-R --files-from="/source/folders.txt" /  /destination/folders --remove-source-files

我甚至在末尾添加了--include="*",但它仍然只将所有文件夹复制到新位置。它忽略了它们的所有内容,也没有--remove-source-files。所以我最后只在两个地方放了一堆文件夹,忽略了源文件。

sourcedestination都位于同一卷上。我该如何做到这一点?

EDIT——有人问了一个folders.txt文件内容的例子:

/volume1/Music/Media/Thee Milkshakes/Sing and Play 20 Rock and Roll Hits of the 50's and 60's (1991)
/volume1/Music/Media/Tony Bennett/Playin' With My Friends- Bennett Sings the Blues (2001)
/volume1/Music/Media/Thee Headcoats/The Kids Are All Square- This Is Hip! (1990)
/volume1/Music/Media/Tiger Army/II- Power of Moonlite (2001)
/volume1/Music/Media/T. Rex/Prophets, Seers & Sages- The Angels of the Ages (1968)
/volume1/Music/Media/Ted Leo and the Pharmacists/Mo' Living (2007)
/volume1/Music/Media/Ted Leo and the Pharmacists/tej leo(!), Rx + pharmacists (1999)
/volume1/Music/Media/Ted Leo and the Pharmacists/Tell Balgeary, Balgury Is Dead (Plus Solo!) (2003)
/volume1/Music/Media/Teenage Fanclub/Sparky's Dream (1995)
/volume1/Music/Media/Teenage Fanclub/Words of Wisdom & Hope (2002)
/volume1/Music/Media/Teenage Fanclub/God Knows It's True (1990)

--remove-source-files不会删除FOLDERS。它会删除文件。在rsync之后,您需要为cleanup编写一个额外的脚本,或者使用mv

我甚至想说mv可能会更好,因为你没有通过网络传输文件。

下面是要附加到rsync的脚本的近似值(因为我不知道folders.txt的内容(。

rsync -avPh --no-R --files-from="/source/folders.txt" /  /destination/folders --remove-source-files
while IFS= read -r src; do
find $src -type d -empty -delete
done < source/folders.txt

这里有一个mv示例:

while IFS= read -r src; do
mv "$src" "destination/folders/$src"
done < source/folders.txt

最新更新