Jump to content
Sign in to follow this  
Tjlejeune

Move large folders with script

5 posts in this topic Last Reply

Recommended Posts

Posted (edited)

Need some help. I'm trying to set up unraid to move any folder larger than 5G in my download folder to a watch folder I have set up with the handbrake docker. Any one know how I can accomplish this? 

Edited by Tjlejeune

Share this post


Link to post
Posted (edited)

Here is a script you can use.  Just replace source and target with your folder paths.

#!/bin/bash

limit=4G
source="/mnt/user/source"
target="/mnt/user/target"

limit=$(echo $limit | cut -d 'G' -f 1)

for dir in "$source"/*/
do
	size=$(du -sBG "$dir" | cut -d 'G' -f 1)

	if (( $size > $limit ))
	then
		echo $size\G $dir \-\> $target
		mv "$dir" "$target"
	fi
done

moveDirBySize.sh

Edited by JoeUnraidUser
updated to handle spaces in folder names

Share this post


Link to post
Posted (edited)
2 hours ago, Tjlejeune said:

Thank you. Works as long as there's no spaces in the folder name

Try it now.  I updated it to handle spaces in folder names.

Edited by JoeUnraidUser

Share this post


Link to post

Oh, quotes were needed around $target. Tried fixing that myself but missed that. Thanks again

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this