Bash - 将已装载的fs中的多个子文件夹存档到本地文件夹

时间:2018-06-09 01:54:51

标签: bash for-loop rar

我认为我的想法很简单但是因为我现在花了4小时,我以为我需要帮助。

我想从存储在已安装的fs上的音乐库创建rar-archives,每个档案库都有子文件夹名称,但我希望在本地系统上直接创建档案。

以下两个解决方案都是在图书馆中创建档案,而不是在我的本地fs上。

 for folder in /mnt/storage01/lib/audiobook/entertainment*/; do rar a -m5 -v100m -r "${folder%/}.rar" "$folder"; done

find /mnt/storage01/lib/audiobook/entertainment/. -mindepth 1 -maxdepth 1 -exec rar a -m5 -v100m -r -w {}.rar {} \;

添加

 ... -v100m -r -w "../home/{}.rar" {} \;     
不幸的是,最后只有一个档案名为" home.rar"所有子文件夹都被收集的地方。至少在我当地的fs ..

我在监督什么?

1 个答案:

答案 0 :(得分:0)

使用find with read / while:

    # -- sample code (replace echo output with actual command) --
    save_folder="/tmp/"
    find /tmp/testing/ -maxdepth 1  -type d | while read fpath; do
        echo "rar a -m5 -v100m -r \"${save_folder}$(basename ${fpath%.*}).rar\" \"$fpath\""     
    done

输出(只是回显):

rar a -m5 -v100m -r "/tmp/14.rar" "/tmp/testing/14"
rar a -m5 -v100m -r "/tmp/80.rar" "/tmp/testing/80"
rar a -m5 -v100m -r "/tmp/13.rar" "/tmp/testing/13"
rar a -m5 -v100m -r "/tmp/16.rar" "/tmp/testing/16"
rar a -m5 -v100m -r "/tmp/2.rar" "/tmp/testing/2"
rar a -m5 -v100m -r "/tmp/100.rar" "/tmp/testing/100"
rar a -m5 -v100m -r "/tmp/17.rar" "/tmp/testing/17"