bally12345 Posted April 20, 2019 Share Posted April 20, 2019 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. Quote Link to comment
bally12345 Posted May 17, 2019 Author Share Posted May 17, 2019 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. Quote Link to comment
JoeUnraidUser Posted May 17, 2019 Share Posted May 17, 2019 (edited) 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 May 22, 2019 by JoeUnraidUser Renamed script. 2 1 Quote Link to comment
bally12345 Posted May 21, 2019 Author Share Posted May 21, 2019 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:~# Quote Link to comment
bally12345 Posted May 21, 2019 Author Share Posted May 21, 2019 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 Quote Link to comment
bally12345 Posted May 21, 2019 Author Share Posted May 21, 2019 (edited) 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 May 21, 2019 by bally12345 typo Quote Link to comment
bally12345 Posted May 21, 2019 Author Share Posted May 21, 2019 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 Hopefully Radarr will detect the missing 4K movies and download using 1080p profile. Sent from my SM-G973F using Tapatalk Quote Link to comment
JoeUnraidUser Posted May 21, 2019 Share Posted May 21, 2019 Glad you like the script, thanks. 1 Quote Link to comment
bally12345 Posted May 21, 2019 Author Share Posted May 21, 2019 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 Quote Link to comment
JoeUnraidUser Posted May 21, 2019 Share Posted May 21, 2019 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? Quote Link to comment
bally12345 Posted May 21, 2019 Author Share Posted May 21, 2019 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 Quote Link to comment
JoeUnraidUser Posted May 22, 2019 Share Posted May 22, 2019 (edited) 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 May 22, 2019 by JoeUnraidUser Changed wording. 1 Quote Link to comment
bally12345 Posted May 22, 2019 Author Share Posted May 22, 2019 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. 1 Quote Link to comment
piratx Posted October 1, 2019 Share Posted October 1, 2019 Thank you JoeUnraidUser for these amazing script. I was trying to find a way to kill nzbget leftovers and those helped a lot Quote Link to comment
KRONZO Posted December 7, 2021 Share Posted December 7, 2021 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 Quote Link to comment
JC2020 Posted July 26, 2022 Share Posted July 26, 2022 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. Quote Link to comment
PartyingChair Posted April 24, 2023 Share Posted April 24, 2023 (edited) 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 April 24, 2023 by PartyingChair Quote Link to comment
JoeUnraidUser Posted April 24, 2023 Share Posted April 24, 2023 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"/.*/ Quote Link to comment
PartyingChair Posted April 25, 2023 Share Posted April 25, 2023 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! Quote Link to comment
beinghitesh Posted June 7, 2023 Share Posted June 7, 2023 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 Quote Link to comment
Recommended Posts
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.