Skip to content
View in the app

A better way to browse. Learn more.

Unraid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Clean up command for folders under 10mb?

Featured Replies

Is there a plugin or a script I can use to run on my "Movies" folder to delete all folders that are less than 10mb in size?

 

I have a lot of old folders that are left over that have thumbnails, nfo etc but no movies. Just want to remove these without manually checking each folder.

  • 4 weeks later...
  • Author

Bump 

Does anyone have suggestion on how to remove empty folders or folders with *.mkv *,mp4 less than 100mb

 

I did install QDirStat but get permission error when I try to delete.

Here is a script that will remove directories within a source directory less than a certain size limit.  I used 100M, but you can change it to any size in MB.  The script can be easily changed to KB, GB, TB etc...  Don't forget to set your source directory.

#!/bin/bash

limit=100M
source="/mnt/user/Movies"

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

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

	if (( $limit > $size ))
	then
		echo remove: $dir
		rm -rf "$dir"
	fi
done

removeDirUnderSize.sh

Edited by JoeUnraidUser
Renamed script.

  • Author

Hi thanks for providing this, just having a slight issue running it.


I changed the source to a test folder with 4 folders 2 with movies, nfo and jpg and 2 folders with just nfo and jpg and no movies but

limit=100M
source="/mnt/user/Downloads/data/test"

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

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

	if (( $limit > $size ))
	then
		echo remove: $dir
		rm -rf "$dir"
	if
done

I get the following error

root@Server:~# /mnt/user/Downloads/data/test/cleanupscript.sh
/mnt/user/Downloads/data/test/cleanupscript.sh: line 3: $'\r': command not found
/mnt/user/Downloads/data/test/cleanupscript.sh: line 5: $'\r': command not found
/mnt/user/Downloads/data/test/cleanupscript.sh: line 7: syntax error near unexpected token `$'do\r''
'mnt/user/Downloads/data/test/cleanupscript.sh: line 7: `do
root@Server:~# 
  • Author

Ignore me didnt copying it correctly. Missed the #!/bin/bash from the top but was using notepad++ and it still didnt like it.

 

Copied your attached file and modified using notepad.exe and worked perfectly. The 2 folders with nothing but .nfo and .jpg in there were removed and the other to folders with movies remained.

 

Will run on my entire movie folder now to clean it up :)

 

Many thanks

  • Author

36 folders removed very pleased was expecting a lot more they were mainly duplicates that were removed from plex but the folder remained on share.

 

Is there a way to change it so I can delete folders larger than say 20gb? When I moved to Radarr I didnt set my profiles correctly and got loads of 4k version I dont actually need.

Edited by bally12345
typo

  • Author

Ended up filtering movies in Plex by Resolution then manually deleted the 4K versions if there is just a single file in the folder plex removes the folder but if there's any extra files like subs or nfo it deletes the movie file and leaves the folder.

This cleanup script has done a brilliant job [emoji106]

Hopefully Radarr will detect the missing 4K movies and download using 1080p profile.

Sent from my SM-G973F using Tapatalk

Glad you like the script, thanks.

  • Author
Glad you like the script, thanks.
Is there a quick way to modify the script to remove movies over 20GB have a whole load of high bitrate 1080p movies that are just too large for my liking.

Sent from my SM-G973F using Tapatalk

I have to go out for dinner now, but I will write it up later on this evening.  Are you looking to just delete .mpg and .mkv files or do you  want to delete any file over 20GB?  Do you just want the files removed or the whole directory?

  • Author
I have to go out for dinner now, but I will write it up later on this evening.  Are you looking to just delete .mpg and .mkv files or do you  want to delete any file over 20GB?  Do you just want the files removed or the whole directory?
Remove the whole folder, or just delete the mkv/mp4 etc then I can run the cleanup script.

Either way no rush. Just helps to recover some valuable space.

Many thanks

Sent from my SM-G973F using Tapatalk

I know this is overkill, but it only took about 15 minutes.  Here are 3 different scripts for different situations:

 

Remove directories within a source directory over a certain size:

#!/bin/bash

limit=20G
source="/mnt/user/Movies"

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 remove: $dir
		rm -rf "$dir"
	fi
done

removeDirOverSize.sh

 

Remove files within a source directory over a certain size:

#!/bin/bash

limit=20G
source="/mnt/user/Movies"

find "$source" -type f -size +$limit -delete -print

removeFilesOverSize.sh

 

Remove files within a source directory over a certain size with specific extensions:

#!/bin/bash

limit=20G
source="/mnt/user/Movies"

find "$source" -regextype posix-extended -iregex '.*\.(mpg|mkv)' -size +$limit -delete -print

To change extensions you could replace mpg|mkv with avi or mpg|mkv|avi etc...

removeFilesOverSizeByExtension.sh

 

Edited by JoeUnraidUser
Changed wording.

  • Author

Many thanks, saved me tons of space. will keep these safe as they come in very handy. I am pretty sure Radarr doesn't download smaller versions if you change profile or the cutoff.

 

 

  • 4 months later...

Thank you JoeUnraidUser for these amazing script. I was trying to find a way to kill nzbget leftovers and those helped a lot :)

  • 2 years later...

Hi

 

Just found this it's very cool :) and works great.

could this be modified to work recursively, right now i have to set up 8 different script with each their path.

my folder structure is like this.

data/media/movies/

abcd

efgh

..... 

 

so i would like to point it to my top movie folder, could this be done.

 

thanks :)

  • 7 months later...

Is there any way to put a path in and this go thru folders one or two folders deep?  For instance, I use path /mnt/user/Music, but have Artist then Album and I want it to delete Albums that have no file.  Lidarr isn't cleaning them up because they have a 100KB cover art and you script works but will only delete the Artist folder if it's empty.  I have a rather large collection and am hoping I don't have to go folder by folder.

  • 8 months later...
On 5/17/2019 at 4:23 PM, JoeUnraidUser said:

Here is a script that will remove directories within a source directory less than a certain size limit.  I used 100M, but you can change it to any size in MB.  The script can be easily changed to KB, GB, TB etc...  Don't forget to set your source directory.

#!/bin/bash

limit=100M
source="/mnt/user/Movies"

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

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

	if (( $limit > $size ))
	then
		echo remove: $dir
		rm -rf "$dir"
	fi
done

removeDirUnderSize.sh 237 B · 30 downloads

Hey,

 

I copy and pasted that, the copy and pasted the directory in that I want to finish with this: 

 

#!/bin/bash

 

limit=10M
source="/mnt/user/Media/Ingress/Compressed"

 

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

 

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

 

    if (( $limit > $size ))
    then
        echo remove: $dir
        rm -rf "$dir"
    fi


done

 

 

But I get error 

du: cannot access '/mnt/user/Media/Ingress/Compressed/*/': No such file or directory
/tmp/user.scripts/tmpScripts/Delete empty compressed folders/script: line 12: ((: 10000000 > : syntax error: operand expected (error token is "> ")

 

This is what the folder looks like, I am trying to deleted the folder ".ISdr1c"

 

For more info, this is a temporary folder created by handbrake when it is compressing my files. it deletes it on it's own, but I want to automatically turn off handbrake in the morning and when I do that, it DOES leave those folders there. 

 

Do you know if I need to mofify something in your script to make it work?

 

Thanks in advance! 

Edited by PartyingChair

7 hours ago, PartyingChair said:

Hey,

 

I copy and pasted that, the copy and pasted the directory in that I want to finish with this: 

 

#!/bin/bash

 

limit=10M
source="/mnt/user/Media/Ingress/Compressed"

 

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

 

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

 

    if (( $limit > $size ))
    then
        echo remove: $dir
        rm -rf "$dir"
    fi


done

 

 

But I get error 

du: cannot access '/mnt/user/Media/Ingress/Compressed/*/': No such file or directory
/tmp/user.scripts/tmpScripts/Delete empty compressed folders/script: line 12: ((: 10000000 > : syntax error: operand expected (error token is "> ")

 

This is what the folder looks like, I am trying to deleted the folder ".ISdr1c"

 

For more info, this is a temporary folder created by handbrake when it is compressing my files. it deletes it on it's own, but I want to automatically turn off handbrake in the morning and when I do that, it DOES leave those folders there. 

 

Do you know if I need to mofify something in your script to make it work?

 

Thanks in advance! 

".ISdr1c" is a dot file so the script would not see it.  Try substituting the following line with the "." Infront of the "*":

for dir in "$source"/.*/

29 minutes ago, JoeUnraidUser said:

".ISdr1c" is a dot file so the script would not see it.  Try substituting the following line with the "." Infront of the "*":

for dir in "$source"/.*/

Ah interesting. Thank you! 

  • 1 month later...
On 5/17/2019 at 6:23 PM, JoeUnraidUser said:

Here is a script that will remove directories within a source directory less than a certain size limit.  I used 100M, but you can change it to any size in MB.  The script can be easily changed to KB, GB, TB etc...  Don't forget to set your source directory.

#!/bin/bash

limit=100M
source="/mnt/user/Movies"

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

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

	if (( $limit > $size ))
	then
		echo remove: $dir
		rm -rf "$dir"
	fi
done

removeDirUnderSize.sh 237 B · 30 downloads

This really helped me recently. Thank you so much!

  • 1 year later...
On 7/26/2022 at 9:07 AM, JC2020 said:

Is there any way to put a path in and this go thru folders one or two folders deep?  For instance, I use path /mnt/user/Music, but have Artist then Album and I want it to delete Albums that have no file.  Lidarr isn't cleaning them up because they have a 100KB cover art and you script works but will only delete the Artist folder if it's empty.  I have a rather large collection and am hoping I don't have to go folder by folder.

I would love the same thing. My tv shows folder has many empty folders under each tv show. 

On 7/21/2024 at 1:52 PM, Jurak said:

I would love the same thing. My tv shows folder has many empty folders under each tv show. 

 

I use this tool to remove empty directories:  REMOVE EMPTY DIRECTORIES (AKA RED)

 

You can also use the find command to remove empty directories:  Linux / Unix Find and Delete All Empty Directories & Files

 

#!/bin/bash

usage()
{
   echo "Usage: $0 <directory>"
   echo "example: $0 \"/mnt/user/Media/TV Shows\""
}

while getopts 'h' opt
do
   case $opt in
      h)
         usage
         exit 0
         ;;
   esac
done

shift "$(($OPTIND -1))"

if [ $# -eq 0 ]
then
   echo "ERROR: no directory specified"
   exit 0
fi

find "$1" -empty -type d -delete -print

rmEmptyDirs.sh

Edited by JoeUnraidUser

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...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.