# Move and Delete script for unRAID

**URL:** <https://forum.rclone.org/t/move-and-delete-script-for-unraid/31087>\
**Category:** Help and Support\
**Created:** [June 2, 2022, 10:50am UTC](https://forum.rclone.org/t/move-and-delete-script-for-unraid/31087 "2022-06-02T10:50:59Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![matt3m](https://forum.rclone.org/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@matt3m](https://forum.rclone.org/u/matt3m)\
**Post date:** [June 2, 2022, 10:50am UTC](https://forum.rclone.org/t/move-and-delete-script-for-unraid/31087/1 "2022-06-02T10:50:59Z")

</div>

#### What is the problem you are having with rclone?

I am not having a problem, I would just like some help 🙂

#### Run the command 'rclone version' and share the full output of the command.

```auto
rclone v1.58.1
- os/version: slackware 14.2+ (64 bit)
- os/kernel: 5.10.28-Unraid (x86_64)
- os/type: linux
- os/arch: amd64
- go/version: go1.17.9
- go/linking: static
- go/tags: none

```

#### Which cloud storage system are you using? (eg Google Drive)

SFTP

#### The command you were trying to run (eg `rclone copy /tmp remote:tmp`)

```auto
function DownloadFolders($RemoteRoot, $LocalRoot) {
    rclone lsf --dirs-only --dir-slash=false $RemoteRoot | ForEach-Object {
        $LocalPath = Join-Path -Path $LocalRoot -ChildPath $_
        Remove-Item -Recurse -Force -LiteralPath $LocalPath -ErrorAction Ignore
        rclone move --progress --transfers=1 "${RemoteRoot}/${_}" $LocalPath
    }
    rclone rmdirs $RemoteRoot --leave-root
}
DownloadFolders "ftpserver:test/" "I:\"
DownloadFolders "ftpserver:Another Folder/" "E:\Another Folder"

```

#### The rclone config contents with secrets removed.

```auto
[ftpserver]
type = sftp
host = HOST HERE
user = USERNAME HERE
pass = PASSWORD HERE
md5sum_command = md5sum
sha1sum_command = sha1sum

```

#### A log from the command with the `-vv` flag

```auto
I haven't actually run the command as it's for Powershell instead of Linux.

```

#### Reason for my post

I have been using the above script for a while now and it's been working great (thanks for everyone's help with it), however, I have just built myself a NAS that uses unRAID and I would like to have the same script that I use on Windows to work on unRAID. How can it be converted to work on unRAID?

The original post is here - [Move and Delete](https://forum.rclone.org/t/move-and-delete/29133)

Thanks

---

<div class="post-metadata">

**Author:** ![matt3m](https://forum.rclone.org/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@matt3m](https://forum.rclone.org/u/matt3m)\
**Post date:** [June 3, 2022, 8:38am UTC](https://forum.rclone.org/t/move-and-delete-script-for-unraid/31087/2 "2022-06-03T08:38:31Z")

</div>

I have been trying to find someone on Fiverr to do this script but what does the scirpt need to be written in? Shell?

---

<div class="post-metadata">

**Author:** ![matt3m](https://forum.rclone.org/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@matt3m](https://forum.rclone.org/u/matt3m)\
**Post date:** [June 3, 2022, 11:28am UTC](https://forum.rclone.org/t/move-and-delete-script-for-unraid/31087/3 "2022-06-03T11:28:13Z")

</div>

Would this work? I took what @ncw wrote in my Move and Delete post and edited it a bit.

```auto
for folder in $(rclone lsf --dirs-only "ftpserver:Test Folder"); do
    rm -rf "/mnt/user/Media/Test Folder/${folder}"
    rclone move "ftpserver:Test Folder/${folder}" "/mnt/user/Media/Test Folder/${folder}" --progress --transfers=1 --dry-run
done

```

---

<div class="post-metadata">

**Author:** ![ncw](https://forum.rclone.org/user_avatar/forum.rclone.org/ncw/32/18_2.png) [@ncw](https://forum.rclone.org/u/ncw)\
**Post date:** [June 3, 2022, 1:32pm UTC](https://forum.rclone.org/t/move-and-delete-script-for-unraid/31087/4 "2022-06-03T13:32:33Z")

</div>

You can run powershell scripts on linux:

> **[Install PowerShell on Linux - PowerShell](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-linux?view=powershell-7.2)**
>
> Learn about the Linux distributions supported by PowerShell.

---

<div class="post-metadata">

**Author:** ![matt3m](https://forum.rclone.org/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@matt3m](https://forum.rclone.org/u/matt3m)\
**Post date:** [June 3, 2022, 2:06pm UTC](https://forum.rclone.org/t/move-and-delete-script-for-unraid/31087/5 "2022-06-03T14:06:27Z")

</div>

Thanks Nick. I wasn't aware of that, I'm new to Linux and unRAID. I wouldn't know where to start or how to install it on unRAID.

Would I be better using a script that is written specifically for Linux like the one you wrote before that I edited above? I'm scared to run it as not sure if it will delete everything.

---

<div class="post-metadata">

**Author:** ![matt3m](https://forum.rclone.org/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@matt3m](https://forum.rclone.org/u/matt3m)\
**Post date:** [June 3, 2022, 3:55pm UTC](https://forum.rclone.org/t/move-and-delete-script-for-unraid/31087/6 "2022-06-03T15:55:37Z")

</div>

I bit the bullet and tested the following script:

```auto
for folder in $(rclone lsf --dirs-only "ftpserver:Test Folder"); do
    echo rm -rf "/mnt/user/Media/Test Folder/${folder}"
    rclone move "ftpserver:Test Folder/${folder}" "/mnt/user/Media/Test Folder/${folder}" --progress --transfers=1 --dry-run
done

```

I don't think it worked as intended... This is what I got when running it using the User Scripts plugin:

```auto
Script location: /tmp/user.scripts/tmpScripts/Test/script
Note that closing this window will abort the execution of this script
rm -rf /mnt/user/Media/Test Folder/Folder

2022-06-03 16:46:21 ERROR : sftp://username@serveraddress.com:22/Test Folder/Folder: error reading source root directory: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Elapsed time: 0.2s
2022-06-03 16:46:21 ERROR : Attempt 1/3 failed with 1 errors and: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.2s
2022-06-03 16:46:21 ERROR : sftp://username@serveraddress.com:22/Test Folder/Folder: error reading source root directory: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Elapsed time: 0.2s
2022-06-03 16:46:21 ERROR : Attempt 2/3 failed with 1 errors and: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.2s
2022-06-03 16:46:21 ERROR : sftp://username@serveraddress.com:22/Test Folder/Folder: error reading source root directory: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Elapsed time: 0.2s
2022-06-03 16:46:21 ERROR : Attempt 3/3 failed with 1 errors and: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.2sTransferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.2s
2022/06/03 16:46:21 NOTICE:
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.2s

2022/06/03 16:46:21 Failed to move: directory not found
rm -rf /mnt/user/Media/Test Folder/1/

2022-06-03 16:46:22 ERROR : sftp://username@serveraddress.com:22/Test Folder/1/: error reading source root directory: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Elapsed time: 0.2s
2022-06-03 16:46:22 ERROR : Attempt 1/3 failed with 1 errors and: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.2s
2022-06-03 16:46:22 ERROR : sftp://username@serveraddress.com:22/Test Folder/1/: error reading source root directory: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Elapsed time: 0.2s
2022-06-03 16:46:22 ERROR : Attempt 2/3 failed with 1 errors and: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.2s
2022-06-03 16:46:22 ERROR : sftp://username@serveraddress.com:22/Test Folder/1/: error reading source root directory: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Elapsed time: 0.2s
2022-06-03 16:46:22 ERROR : Attempt 3/3 failed with 1 errors and: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.2sTransferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.2s
2022/06/03 16:46:22 NOTICE:
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.2s

2022/06/03 16:46:22 Failed to move: directory not found
rm -rf /mnt/user/Media/Test Folder/Folder

2022-06-03 16:46:22 ERROR : sftp://username@serveraddress.com:22/Test Folder/Folder: error reading source root directory: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Elapsed time: 0.2s
2022-06-03 16:46:22 ERROR : Attempt 1/3 failed with 1 errors and: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.2s
2022-06-03 16:46:22 ERROR : sftp://username@serveraddress.com:22/Test Folder/Folder: error reading source root directory: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Elapsed time: 0.2s
2022-06-03 16:46:22 ERROR : Attempt 2/3 failed with 1 errors and: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.2s
2022-06-03 16:46:22 ERROR : sftp://username@serveraddress.com:22/Test Folder/Folder: error reading source root directory: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Elapsed time: 0.2s
2022-06-03 16:46:22 ERROR : Attempt 3/3 failed with 1 errors and: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.2sTransferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.2s
2022/06/03 16:46:22 NOTICE:
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.2s

2022/06/03 16:46:22 Failed to move: directory not found
rm -rf /mnt/user/Media/Test Folder/2/

2022-06-03 16:46:22 ERROR : sftp://username@serveraddress.com:22/Test Folder/2/: error reading source root directory: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Elapsed time: 0.2s
2022-06-03 16:46:22 ERROR : Attempt 1/3 failed with 1 errors and: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.2s
2022-06-03 16:46:22 ERROR : sftp://username@serveraddress.com:22/Test Folder/2/: error reading source root directory: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Elapsed time: 0.2s
2022-06-03 16:46:22 ERROR : Attempt 2/3 failed with 1 errors and: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.2s
2022-06-03 16:46:22 ERROR : sftp://username@serveraddress.com:22/Test Folder/2/: error reading source root directory: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Elapsed time: 0.2s
2022-06-03 16:46:22 ERROR : Attempt 3/3 failed with 1 errors and: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.2sTransferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.2s
2022/06/03 16:46:22 NOTICE:
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.2s

2022/06/03 16:46:22 Failed to move: directory not found
rm -rf /mnt/user/Media/Test Folder/Folder

2022-06-03 16:46:22 ERROR : sftp://username@serveraddress.com:22/Test Folder/Folder: error reading source root directory: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Elapsed time: 0.2s
2022-06-03 16:46:22 ERROR : Attempt 1/3 failed with 1 errors and: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.2s
2022-06-03 16:46:22 ERROR : sftp://username@serveraddress.com:22/Test Folder/Folder: error reading source root directory: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Elapsed time: 0.2s
2022-06-03 16:46:22 ERROR : Attempt 2/3 failed with 1 errors and: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.2s
2022-06-03 16:46:22 ERROR : sftp://username@serveraddress.com:22/Test Folder/Folder: error reading source root directory: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Elapsed time: 0.2s
2022-06-03 16:46:22 ERROR : Attempt 3/3 failed with 1 errors and: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.2sTransferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.2s
2022/06/03 16:46:22 NOTICE:
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.2s

2022/06/03 16:46:22 Failed to move: directory not found
rm -rf /mnt/user/Media/Test Folder/3/

2022-06-03 16:46:23 ERROR : sftp://username@serveraddress.com:22/Test Folder/3/: error reading source root directory: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Elapsed time: 0.2s
2022-06-03 16:46:23 ERROR : Attempt 1/3 failed with 1 errors and: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.2s
2022-06-03 16:46:23 ERROR : sftp://username@serveraddress.com:22/Test Folder/3/: error reading source root directory: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Elapsed time: 0.2s
2022-06-03 16:46:23 ERROR : Attempt 2/3 failed with 1 errors and: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.2s
2022-06-03 16:46:23 ERROR : sftp://username@serveraddress.com:22/Test Folder/3/: error reading source root directory: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Elapsed time: 0.2s
2022-06-03 16:46:23 ERROR : Attempt 3/3 failed with 1 errors and: directory not found
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.2sTransferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.2s
2022/06/03 16:46:23 NOTICE:
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.2s

2022/06/03 16:46:23 Failed to move: directory not found

```

The structure inside the Test Folder is as follows:

```auto
Folder 1
- file_example_MP3_1MG.mp3

Folder 2
- file_example_MP3_2MG.mp3

Folder 3
 - file_example_MP3_5MG.mp3

```

Sorry for so many posts, I'm just eager to get this working and trying to understand/learn what is going wrong/how to get it to work.

---

<div class="post-metadata">

**Author:** ![matt3m](https://forum.rclone.org/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@matt3m](https://forum.rclone.org/u/matt3m)\
**Post date:** [June 4, 2022, 10:58am UTC](https://forum.rclone.org/t/move-and-delete-script-for-unraid/31087/7 "2022-06-04T10:58:48Z")

</div>

From my research it looks like the for loop doesn't like the use of ls or in this case lsf. So, I'm not sure how to get around that.

---

<div class="post-metadata">

**Author:** ![ncw](https://forum.rclone.org/user_avatar/forum.rclone.org/ncw/32/18_2.png) [@ncw](https://forum.rclone.org/u/ncw)\
**Post date:** [June 4, 2022, 4:56pm UTC](https://forum.rclone.org/t/move-and-delete-script-for-unraid/31087/8 "2022-06-04T16:56:29Z")

</div>

Your script looks pretty good.

Try putting `echo` in front of the rclone statements too and see if you can spot what is going wrong

```auto
for folder in $(rclone lsf --dirs-only "ftpserver:Test Folder"); do
    echo rm -rf "/mnt/user/Media/Test Folder/${folder}"
    echo rclone move "ftpserver:Test Folder/${folder}" "/mnt/user/Media/Test Folder/${folder}" --progress --transfers=1 --dry-run
done

```

---

<div class="post-metadata">

**Author:** ![matt3m](https://forum.rclone.org/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@matt3m](https://forum.rclone.org/u/matt3m)\
**Post date:** [June 4, 2022, 5:23pm UTC](https://forum.rclone.org/t/move-and-delete-script-for-unraid/31087/9 "2022-06-04T17:23:33Z")

</div>

Thanks Nick.

To me it looks like the folders are being split up after a space. So I currently have these folders on the remote:

Test 1/  
Test 2/  
Test 3/

And the output of the script is the following:

```auto
Script location: /tmp/user.scripts/tmpScripts/Test/script
Note that closing this window will abort the execution of this script
rm -rf /mnt/user/Media/Test Folder/Test
rclone move ftpserver:Test Folder/Test /mnt/user/Media/Test Folder/Test --progress --transfers=1 --dry-run
rm -rf /mnt/user/Media/Test Folder/1/
rclone move ftpserver:Test Folder/1/ /mnt/user/Media/Test Folder/1/ --progress --transfers=1 --dry-run
rm -rf /mnt/user/Media/Test Folder/Test
rclone move ftpserver:Test Folder/Test /mnt/user/Media/Test Folder/Test --progress --transfers=1 --dry-run
rm -rf /mnt/user/Media/Test Folder/2/
rclone move ftpserver:Test Folder/2/ /mnt/user/Media/Test Folder/2/ --progress --transfers=1 --dry-run
rm -rf /mnt/user/Media/Test Folder/Test
rclone move ftpserver:Test Folder/Test /mnt/user/Media/Test Folder/Test --progress --transfers=1 --dry-run
rm -rf /mnt/user/Media/Test Folder/3/
rclone move ftpserver:Test Folder/3/ /mnt/user/Media/Test Folder/3/ --progress --transfers=1 --dry-run

```

It thinks that there's the following folders:

Test  
1  
2  
3

I have tried what is suggested here but it hasn't worked - [https://www.cyberciti.biz/tips/handling-filenames-with-spaces-in-bash.html](https://www.cyberciti.biz/tips/handling-filenames-with-spaces-in-bash.html)

---

<div class="post-metadata">

**Author:** ![Subside9654](https://forum.rclone.org/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@Subside9654](https://forum.rclone.org/u/Subside9654)\
**Post date:** [June 5, 2022, 1:31pm UTC](https://forum.rclone.org/t/move-and-delete-script-for-unraid/31087/10 "2022-06-05T13:31:11Z")

</div>

Just taking a shot in the dark here, but in your script try putting your variable in double quotes.

`rm -rf "/mnt/user/Media/Test Folder/"${folder}""`

---

<div class="post-metadata">

**Author:** ![matt3m](https://forum.rclone.org/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@matt3m](https://forum.rclone.org/u/matt3m)\
**Post date:** [June 5, 2022, 1:49pm UTC](https://forum.rclone.org/t/move-and-delete-script-for-unraid/31087/11 "2022-06-05T13:49:29Z")

</div>

Thanks, I just tried that and it's still splitting the folders.

```auto
Script location: /tmp/user.scripts/tmpScripts/Test/script
Note that closing this window will abort the execution of this script
rm -rf /mnt/user/Media/Test Folder/Test
rclone move ftpserver:Test Folder/Test /mnt/user/Media/Test Folder/Test --progress --transfers=1 --dry-run
rm -rf /mnt/user/Media/Test Folder/1/
rclone move ftpserver:Test Folder/1/ /mnt/user/Media/Test Folder/1/ --progress --transfers=1 --dry-run
rm -rf /mnt/user/Media/Test Folder/Test
rclone move ftpserver:Test Folder/Test /mnt/user/Media/Test Folder/Test --progress --transfers=1 --dry-run
rm -rf /mnt/user/Media/Test Folder/2/
rclone move ftpserver:Test Folder/2/ /mnt/user/Media/Test Folder/2/ --progress --transfers=1 --dry-run
rm -rf /mnt/user/Media/Test Folder/Test
rclone move ftpserver:Test Folder/Test /mnt/user/Media/Test Folder/Test --progress --transfers=1 --dry-run
rm -rf /mnt/user/Media/Test Folder/3/
rclone move ftpserver:Test Folder/3/ /mnt/user/Media/Test Folder/3/ --progress --transfers=1 --dry-run

```

---

<div class="post-metadata">

**Author:** ![albertony](https://forum.rclone.org/user_avatar/forum.rclone.org/albertony/32/8586_2.png) [@albertony](https://forum.rclone.org/u/albertony)\
**Post date:** [June 5, 2022, 3:32pm UTC](https://forum.rclone.org/t/move-and-delete-script-for-unraid/31087/12 "2022-06-05T15:32:29Z")

</div>

Using `while read` loop instead is the solution, I think, see this for inspiration: [RClone / Bash - Loop through and download all files in directory individually - Stack Overflow](https://stackoverflow.com/a/47501397)

Edit: Maybe like this:

```auto
while read -r folder; do
    echo rm -rf "/mnt/user/Media/Test Folder/${folder}"
    echo rclone move "ftpserver:Test Folder/${folder}" "/mnt/user/Media/Test Folder/${folder}" --progress --transfers=1 --dry-run
done < <(rclone lsf --dirs-only "ftpserver:Test Folder")

```

---

<div class="post-metadata">

**Author:** ![matt3m](https://forum.rclone.org/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@matt3m](https://forum.rclone.org/u/matt3m)\
**Post date:** [June 5, 2022, 4:00pm UTC](https://forum.rclone.org/t/move-and-delete-script-for-unraid/31087/13 "2022-06-05T16:00:32Z")

</div>

Thank you. I think that's very close. It's leaving the folders on the remote and then when it's run again it then deletes the folders on local.

Would I add `rclone rmdirs --leave-root` onto the end?

---

<div class="post-metadata">

**Author:** ![albertony](https://forum.rclone.org/user_avatar/forum.rclone.org/albertony/32/8586_2.png) [@albertony](https://forum.rclone.org/u/albertony)\
**Post date:** [June 5, 2022, 5:24pm UTC](https://forum.rclone.org/t/move-and-delete-script-for-unraid/31087/14 "2022-06-05T17:24:08Z")

</div>

> [@matt3m](#):
>
> It's leaving the folders on the remote

What do you mean? Does it move the content but leaves the `"ftpserver:Test Folder/${folder}"` behind as empty folder or what? Running with `-vv` might give some relevant hints.

---

<div class="post-metadata">

**Author:** ![matt3m](https://forum.rclone.org/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@matt3m](https://forum.rclone.org/u/matt3m)\
**Post date:** [June 5, 2022, 5:38pm UTC](https://forum.rclone.org/t/move-and-delete-script-for-unraid/31087/15 "2022-06-05T17:38:06Z")

</div>

That's right it leaves the empty folders behind.

Below is the output when running -vv

```auto
Script location: /tmp/user.scripts/tmpScripts/Test/script
Note that closing this window will abort the execution of this script
2022/06/05 18:33:42 DEBUG : rclone: Version "v1.58.1" starting with parameters ["rcloneorig" "--config" "/boot/config/plugins/rclone/.rclone.conf" "move" "ftpserver:Test Folder/Test 1/" "/mnt/user/Media/Test Folder/Test 1/" "--progress" "--transfers=1" "-vv"]
2022/06/05 18:33:42 DEBUG : Creating backend with remote "ftpserver:Test Folder/Test 1/"
2022/06/05 18:33:42 DEBUG : Using config file from "/boot/config/plugins/rclone/.rclone.conf"
2022/06/05 18:33:42 DEBUG : sftp://username@serveraddress.com:22/Test Folder/Test 1/: New connection 192.168.0.51:38142->185.21.216.160:22 to "SSH-2.0-OpenSSH_7.4p1 Debian-10+deb9u7"
2022/06/05 18:33:42 DEBUG : sftp://username@serveraddress.com:22/Test Folder/Test 1/: Using absolute root directory "/media/sdh1/matt3/Test Folder/Test 1"
2022/06/05 18:33:42 DEBUG : Creating backend with remote "/mnt/user/Media/Test Folder/Test 1/"

2022-06-05 18:33:42 DEBUG : Local file system at /mnt/user/Media/Test Folder/Test 1/: Waiting for checks to finish
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Checks: 0 / 1, 0%
Transferred: 0 / 1, 0%
Elapsed time: 0.2s
Checking:

Transferring:
* file_example_MP3_5MG.mp3: transferring
2022-06-05 18:33:42 DEBUG : Local file system at /mnt/user/Media/Test Folder/Test 1/: Waiting for transfers to finish
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Checks: 0 / 1, 0%
Transferred: 0 / 1, 0%
Elapsed time: 0.2s
Checking:

Transferring:
* file_example_MP3_5MG.mp3: transferringTransferred: 2.996 MiB / 5.044 MiB, 59%, 0 B/s, ETA -
Checks: 0 / 1, 0%
Transferred: 0 / 1, 0%
Elapsed time: 0.7s
Checking:

Transferring:
* file_example_MP3_5MG.mp3: 59% /5.044Mi, 0/s, -
2022-06-05 18:33:43 DEBUG : sftp://username@serveraddress.com:22/Test Folder/Test 1/: Running remote command: md5sum /media/sdh1/matt3/Test\ Folder/Test\ 1/file_example_MP3_5MG.mp3
Transferred: 5.044 MiB / 5.044 MiB, 100%, 0 B/s, ETA -
Checks: 0 / 1, 0%
Transferred: 0 / 1, 0%
Elapsed time: 0.9s
Checking:

Transferring:
* file_example_MP3_5MG.mp3:100% /5.044Mi, 0/s, -
2022-06-05 18:33:43 DEBUG : sftp://username@serveraddress.com:22/Test Folder/Test 1/: Remote command result: 2688ed914ed6315229fb89e1e916cdee /media/sdh1/matt3/Test Folder/Test 1/file_example_MP3_5MG.mp3
Transferred: 5.044 MiB / 5.044 MiB, 100%, 0 B/s, ETA -
Checks: 0 / 1, 0%
Transferred: 0 / 1, 0%
Elapsed time: 0.9s
Checking:

Transferring:
* file_example_MP3_5MG.mp3:100% /5.044Mi, 0/s, -
2022-06-05 18:33:43 DEBUG : file_example_MP3_5MG.mp3: md5 = 2688ed914ed6315229fb89e1e916cdee OK
Transferred: 5.044 MiB / 5.044 MiB, 100%, 0 B/s, ETA -
Checks: 0 / 1, 0%
Transferred: 0 / 1, 0%
Elapsed time: 0.9s
Checking:

Transferring:
* file_example_MP3_5MG.mp3:100% /5.044Mi, 0/s, -
2022-06-05 18:33:43 INFO : file_example_MP3_5MG.mp3: Copied (new)
Transferred: 5.044 MiB / 5.044 MiB, 100%, 0 B/s, ETA -
Checks: 0 / 1, 0%
Transferred: 0 / 1, 0%
Elapsed time: 0.9s
Checking:

Transferring:
* file_example_MP3_5MG.mp3:100% /5.044Mi, 0/s, -
2022-06-05 18:33:43 INFO : file_example_MP3_5MG.mp3: Deleted
Transferred: 5.044 MiB / 5.044 MiB, 100%, 0 B/s, ETA -
Checks: 0 / 1, 0%
Deleted: 1 (files), 0 (dirs)
Transferred: 1 / 1, 100%
Elapsed time: 0.9s
Checking:
* file_example_MP3_5MG.mp3: checkingTransferred: 5.044 MiB / 5.044 MiB, 100%, 0 B/s, ETA -
Checks: 2 / 2, 100%
Deleted: 1 (files), 0 (dirs)
Renamed: 1
Transferred: 1 / 1, 100%
Elapsed time: 0.9s
2022/06/05 18:33:43 INFO :
Transferred: 5.044 MiB / 5.044 MiB, 100%, 0 B/s, ETA -
Checks: 2 / 2, 100%
Deleted: 1 (files), 0 (dirs)
Renamed: 1
Transferred: 1 / 1, 100%
Elapsed time: 0.9s

2022/06/05 18:33:43 DEBUG : 13 go routines active
2022/06/05 18:33:43 DEBUG : rclone: Version "v1.58.1" starting with parameters ["rcloneorig" "--config" "/boot/config/plugins/rclone/.rclone.conf" "move" "ftpserver:Test Folder/Test 2/" "/mnt/user/Media/Test Folder/Test 2/" "--progress" "--transfers=1" "-vv"]
2022/06/05 18:33:43 DEBUG : Creating backend with remote "ftpserver:Test Folder/Test 2/"
2022/06/05 18:33:43 DEBUG : Using config file from "/boot/config/plugins/rclone/.rclone.conf"
2022/06/05 18:33:43 DEBUG : sftp://username@serveraddress.com:22/Test Folder/Test 2/: New connection 192.168.0.51:38144->185.21.216.160:22 to "SSH-2.0-OpenSSH_7.4p1 Debian-10+deb9u7"
2022/06/05 18:33:43 DEBUG : sftp://username@serveraddress.com:22/Test Folder/Test 2/: Using absolute root directory "/media/sdh1/matt3/Test Folder/Test 2"
2022/06/05 18:33:43 DEBUG : Creating backend with remote "/mnt/user/Media/Test Folder/Test 2/"

2022-06-05 18:33:43 DEBUG : Local file system at /mnt/user/Media/Test Folder/Test 2/: Waiting for checks to finish
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Checks: 0 / 1, 0%
Transferred: 0 / 1, 0%
Elapsed time: 0.2s
Checking:

Transferring:
* file_example_MP3_2MG.mp3: transferring
2022-06-05 18:33:43 DEBUG : Local file system at /mnt/user/Media/Test Folder/Test 2/: Waiting for transfers to finish
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Checks: 0 / 1, 0%
Transferred: 0 / 1, 0%
Elapsed time: 0.2s
Checking:

Transferring:
* file_example_MP3_2MG.mp3: transferring
2022-06-05 18:33:43 DEBUG : sftp://username@serveraddress.com:22/Test Folder/Test 2/: Running remote command: md5sum /media/sdh1/matt3/Test\ Folder/Test\ 2/file_example_MP3_2MG.mp3
Transferred: 2.016 MiB / 2.016 MiB, 100%, 0 B/s, ETA -
Checks: 0 / 1, 0%
Transferred: 0 / 1, 0%
Elapsed time: 0.6s
Checking:

Transferring:
* file_example_MP3_2MG.mp3:100% /2.016Mi, 0/s, -
2022-06-05 18:33:43 DEBUG : sftp://username@serveraddress.com:22/Test Folder/Test 2/: Remote command result: 0e64629c86cf0b24262122bf2a6eee23 /media/sdh1/matt3/Test Folder/Test 2/file_example_MP3_2MG.mp3
Transferred: 2.016 MiB / 2.016 MiB, 100%, 0 B/s, ETA -
Checks: 0 / 1, 0%
Transferred: 0 / 1, 0%
Elapsed time: 0.6s
Checking:

Transferring:
* file_example_MP3_2MG.mp3:100% /2.016Mi, 0/s, -
2022-06-05 18:33:43 DEBUG : file_example_MP3_2MG.mp3: md5 = 0e64629c86cf0b24262122bf2a6eee23 OK
Transferred: 2.016 MiB / 2.016 MiB, 100%, 0 B/s, ETA -
Checks: 0 / 1, 0%
Transferred: 0 / 1, 0%
Elapsed time: 0.6s
Checking:

Transferring:
* file_example_MP3_2MG.mp3:100% /2.016Mi, 0/s, -
2022-06-05 18:33:43 INFO : file_example_MP3_2MG.mp3: Copied (new)
Transferred: 2.016 MiB / 2.016 MiB, 100%, 0 B/s, ETA -
Checks: 0 / 1, 0%
Transferred: 0 / 1, 0%
Elapsed time: 0.6s
Checking:

Transferring:
* file_example_MP3_2MG.mp3:100% /2.016Mi, 0/s, -
2022-06-05 18:33:43 INFO : file_example_MP3_2MG.mp3: Deleted
Transferred: 2.016 MiB / 2.016 MiB, 100%, 0 B/s, ETA -
Checks: 0 / 1, 0%
Deleted: 1 (files), 0 (dirs)
Transferred: 1 / 1, 100%
Elapsed time: 0.6s
Checking:
* file_example_MP3_2MG.mp3: checkingTransferred: 2.016 MiB / 2.016 MiB, 100%, 0 B/s, ETA -
Checks: 2 / 2, 100%
Deleted: 1 (files), 0 (dirs)
Renamed: 1
Transferred: 1 / 1, 100%
Elapsed time: 0.6s
2022/06/05 18:33:43 INFO :
Transferred: 2.016 MiB / 2.016 MiB, 100%, 0 B/s, ETA -
Checks: 2 / 2, 100%
Deleted: 1 (files), 0 (dirs)
Renamed: 1
Transferred: 1 / 1, 100%
Elapsed time: 0.6s

2022/06/05 18:33:43 DEBUG : 13 go routines active
2022/06/05 18:33:43 DEBUG : rclone: Version "v1.58.1" starting with parameters ["rcloneorig" "--config" "/boot/config/plugins/rclone/.rclone.conf" "move" "ftpserver:Test Folder/Test 3/" "/mnt/user/Media/Test Folder/Test 3/" "--progress" "--transfers=1" "-vv"]
2022/06/05 18:33:43 DEBUG : Creating backend with remote "ftpserver:Test Folder/Test 3/"
2022/06/05 18:33:43 DEBUG : Using config file from "/boot/config/plugins/rclone/.rclone.conf"
2022/06/05 18:33:43 DEBUG : sftp://username@serveraddress.com:22/Test Folder/Test 3/: New connection 192.168.0.51:38146->185.21.216.160:22 to "SSH-2.0-OpenSSH_7.4p1 Debian-10+deb9u7"
2022/06/05 18:33:44 DEBUG : sftp://username@serveraddress.com:22/Test Folder/Test 3/: Using absolute root directory "/media/sdh1/matt3/Test Folder/Test 3"
2022/06/05 18:33:44 DEBUG : Creating backend with remote "/mnt/user/Media/Test Folder/Test 3/"

2022-06-05 18:33:44 DEBUG : Local file system at /mnt/user/Media/Test Folder/Test 3/: Waiting for checks to finish
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Checks: 0 / 1, 0%
Transferred: 0 / 1, 0%
Elapsed time: 0.2s
Checking:

Transferring:
* file_example_MP3_1MG.mp3: transferring
2022-06-05 18:33:44 DEBUG : Local file system at /mnt/user/Media/Test Folder/Test 3/: Waiting for transfers to finish
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Checks: 0 / 1, 0%
Transferred: 0 / 1, 0%
Elapsed time: 0.2s
Checking:

Transferring:
* file_example_MP3_1MG.mp3: transferring
2022-06-05 18:33:44 DEBUG : sftp://username@serveraddress.com:22/Test Folder/Test 3/: Running remote command: md5sum /media/sdh1/matt3/Test\ Folder/Test\ 3/file_example_MP3_1MG.mp3
Transferred: 1.037 MiB / 1.037 MiB, 100%, 0 B/s, ETA -
Checks: 0 / 1, 0%
Transferred: 0 / 1, 0%
Elapsed time: 0.4s
Checking:

Transferring:
* file_example_MP3_1MG.mp3:100% /1.037Mi, 0/s, -
2022-06-05 18:33:44 DEBUG : sftp://username@serveraddress.com:22/Test Folder/Test 3/: Remote command result: ae9120835f658f1ae57e5754811a9475 /media/sdh1/matt3/Test Folder/Test 3/file_example_MP3_1MG.mp3
Transferred: 1.037 MiB / 1.037 MiB, 100%, 0 B/s, ETA -
Checks: 0 / 1, 0%
Transferred: 0 / 1, 0%
Elapsed time: 0.4s
Checking:

Transferring:
* file_example_MP3_1MG.mp3:100% /1.037Mi, 0/s, -
2022-06-05 18:33:44 DEBUG : file_example_MP3_1MG.mp3: md5 = ae9120835f658f1ae57e5754811a9475 OK
Transferred: 1.037 MiB / 1.037 MiB, 100%, 0 B/s, ETA -
Checks: 0 / 1, 0%
Transferred: 0 / 1, 0%
Elapsed time: 0.4s
Checking:

Transferring:
* file_example_MP3_1MG.mp3:100% /1.037Mi, 0/s, -
2022-06-05 18:33:44 INFO : file_example_MP3_1MG.mp3: Copied (new)
Transferred: 1.037 MiB / 1.037 MiB, 100%, 0 B/s, ETA -
Checks: 0 / 1, 0%
Transferred: 0 / 1, 0%
Elapsed time: 0.4s
Checking:

Transferring:
* file_example_MP3_1MG.mp3:100% /1.037Mi, 0/s, -
2022-06-05 18:33:44 INFO : file_example_MP3_1MG.mp3: Deleted
Transferred: 1.037 MiB / 1.037 MiB, 100%, 0 B/s, ETA -
Checks: 0 / 1, 0%
Deleted: 1 (files), 0 (dirs)
Transferred: 1 / 1, 100%
Elapsed time: 0.4s
Checking:
* file_example_MP3_1MG.mp3: checkingTransferred: 1.037 MiB / 1.037 MiB, 100%, 0 B/s, ETA -
Checks: 2 / 2, 100%
Deleted: 1 (files), 0 (dirs)
Renamed: 1
Transferred: 1 / 1, 100%
Elapsed time: 0.4s
2022/06/05 18:33:44 INFO :
Transferred: 1.037 MiB / 1.037 MiB, 100%, 0 B/s, ETA -
Checks: 2 / 2, 100%
Deleted: 1 (files), 0 (dirs)
Renamed: 1
Transferred: 1 / 1, 100%
Elapsed time: 0.4s

2022/06/05 18:33:44 DEBUG : 12 go routines active

```

---

<div class="post-metadata">

**Author:** ![albertony](https://forum.rclone.org/user_avatar/forum.rclone.org/albertony/32/8586_2.png) [@albertony](https://forum.rclone.org/u/albertony)\
**Post date:** [June 5, 2022, 7:45pm UTC](https://forum.rclone.org/t/move-and-delete-script-for-unraid/31087/16 "2022-06-05T19:45:20Z")

</div>

> [@matt3m](#):
>
> Would I add `rclone rmdirs --leave-root` onto the end?

I think you were correct with this. Either `rclone rmdirs "ftpserver:Test Folder/${folder}"` within (at end of) the loop, or `rclone rmdirs --leave-root "ftpserver:Test Folder"` after the loop.

---

<div class="post-metadata">

**Author:** ![matt3m](https://forum.rclone.org/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@matt3m](https://forum.rclone.org/u/matt3m)\
**Post date:** [June 5, 2022, 8:20pm UTC](https://forum.rclone.org/t/move-and-delete-script-for-unraid/31087/17 "2022-06-05T20:20:13Z")

</div>

I tried `rclone rmdirs --leave-root "ftpserver:Test Folder"` at the end of the loop but that didn't seem to work.

However, the below looks like it's working after a few tests. I'll continue to test some more and fingers crossed this seems to be the one.

```auto
while read -r folder; do
    rm -rf "/mnt/user/Media/Test Folder/${folder}"
    rclone move "ftpserver:Test Folder/${folder}" "/mnt/user/Media/Test Folder/${folder}" --progress --transfers=1 -vv
    rclone rmdirs "ftpserver:Test Folder/${folder}"
done < <(rclone lsf --dirs-only "ftpserver:Test Folder")

```

Thanks so much for your help. I tried to find another way to change the for loop before you suggested the while read loop but never came across the while read loop.

---

<div class="post-metadata">

**Author:** ![matt3m](https://forum.rclone.org/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@matt3m](https://forum.rclone.org/u/matt3m)\
**Post date:** [June 6, 2022, 10:07am UTC](https://forum.rclone.org/t/move-and-delete-script-for-unraid/31087/18 "2022-06-06T10:07:09Z")

</div>

After some more testing it looks like the above script works perfectly 🙂

Thanks everyone for the help. I really appreciate it.

---

<div class="post-metadata">

**Author:** ![system](https://forum.rclone.org/uploads/default/original/2X/3/39ad3235f6ffec76ccd0c81616bd55697b4c300d.png) [@system](https://forum.rclone.org/u/system)\
**Post date:** [June 9, 2022, 10:07am UTC](https://forum.rclone.org/t/move-and-delete-script-for-unraid/31087/19 "2022-06-09T10:07:46Z")

</div>

Closed on June 9, 2022, 10:07am UTC

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
