Delete files smaller than XXMB

Come up with a useful post-processing script? Share it here!
solonvault
Newbie
Newbie
Posts: 14
Joined: July 6th, 2012, 4:50 am

Delete files smaller than XXMB

Post by solonvault »

I've searched the forum but couldn't find a script that does this.

I'm looking for a python script to delete files smaller than xxMB after extracting.
This way all the ''junk'' is removed when i download tvshows and movies.
( i know you can auto delete files by file extension in the SAB menu but this is not enough )

Thank you for your help!!
User avatar
sander
Release Testers
Release Testers
Posts: 8832
Joined: January 22nd, 2008, 2:22 pm

Re: Delete files smaller than XXMB

Post by sander »

If (as?) such a Python script is not here, are you willing to write it yourself? Python is a great language, and it will only take a few lines of code.
solonvault
Newbie
Newbie
Posts: 14
Joined: July 6th, 2012, 4:50 am

Re: Delete files smaller than XXMB

Post by solonvault »

I have tried to put something together but it did not work. I have no scripting knowledge what so ever,
So all help is appreciated !!
User avatar
sander
Release Testers
Release Testers
Posts: 8832
Joined: January 22nd, 2008, 2:22 pm

Re: Delete files smaller than XXMB

Post by sander »

solonvault wrote:I have tried to put something together but it did not work. I have no scripting knowledge what so ever,
So all help is appreciated !!
Can you post what you've put together yourself?
exussum
Jr. Member
Jr. Member
Posts: 79
Joined: November 18th, 2010, 2:51 am

Re: Delete files smaller than XXMB

Post by exussum »

find -size -500k -exec rm {\}\ \;

maybe ?
User avatar
sander
Release Testers
Release Testers
Posts: 8832
Joined: January 22nd, 2008, 2:22 pm

Re: Delete files smaller than XXMB

Post by sander »

exussum wrote:find -size -500k -exec rm {\}\ \;

maybe ?
Is that correct syntax? I changed the rm to ls, and that doesn't work:

Code: Select all

sander@toverdoos:~$ find -size -500k -exec ls {\}\ \ ;
find: missing argument to `-exec'
sander@toverdoos:~$ 
Googled some, and this works for me:

Code: Select all

find . -type f -size -500k -exec ls -al {} \;
Is the difference in the ls/rm (and did I introduce the problem myself), or something else?
exussum
Jr. Member
Jr. Member
Posts: 79
Joined: November 18th, 2010, 2:51 am

Re: Delete files smaller than XXMB

Post by exussum »

I remember having to escape more, I should learn to try commands before posting :P

Your way is better than mine - Looking for files too (mine could pick up directory's / links)
User avatar
sander
Release Testers
Release Testers
Posts: 8832
Joined: January 22nd, 2008, 2:22 pm

Re: Delete files smaller than XXMB

Post by sander »

exussum wrote:I remember having to escape more, I should learn to try commands before posting :P

Your way is better than mine - Looking for files too (mine could pick up directory's / links)
Well, thanks for hint towards 'find'.

I seldom use 'find'; I usually "clay" together a one-liner of ls/sed/awk/ etc. Maybe I should use 'find' more.

BTW: in case "claying together" is not correct English: it is Dutch for putting something together in a not too beautiful way.
solonvault
Newbie
Newbie
Posts: 14
Joined: July 6th, 2012, 4:50 am

Re: Delete files smaller than XXMB

Post by solonvault »

Thanks guys!

So the complete code is

Code: Select all

#!/usr/bin/env python

find . -type f -size -500k -exec ls -al {} \;

put this in a .py file

This will delete files smaller than 0,5mb .

Is this correct ?

And will the script only delete files in the ''extract folder'' or all folders ?

Thank you for your reply!
User avatar
sander
Release Testers
Release Testers
Posts: 8832
Joined: January 22nd, 2008, 2:22 pm

Re: Delete files smaller than XXMB

Post by sander »

Well, it is a shell script, not a python script. A shell script runs on Linux / Unix / OSX.

Because you have not yet replied to my question "Can you post what you've put together yourself?", we still don't know which OS you're using ...
exussum
Jr. Member
Jr. Member
Posts: 79
Joined: November 18th, 2010, 2:51 am

Re: Delete files smaller than XXMB

Post by exussum »

also you would have to change the -exec ls -al to -exec rm the first just details the deleted files, the second actually deletes them

edit: a windows version here
http://stackoverflow.com/questions/6764 ... cific-size

or install find from

http://unxutils.sourceforge.net/

and it should work
solonvault
Newbie
Newbie
Posts: 14
Joined: July 6th, 2012, 4:50 am

Re: Delete files smaller than XXMB

Post by solonvault »

im using a Qnap NAS with a other python script working ( prowl ).

i have tried similar script, but thought it where python scripts :-s

do i just put the script

Code: Select all

find . -type f -size -500k -exec ls -al {} \;
in a .sh file and it will work ?

And will the script only delete files in the ''extract folder'' or all folders ?


Thanks again for your help!
solonvault
Newbie
Newbie
Posts: 14
Joined: July 6th, 2012, 4:50 am

Re: Delete files smaller than XXMB

Post by solonvault »

Anyone?? i would think this shouldn't have to be that hard to answer for someone who knows what he's doing..

Thanks!
exussum
Jr. Member
Jr. Member
Posts: 79
Joined: November 18th, 2010, 2:51 am

Re: Delete files smaller than XXMB

Post by exussum »

solonvault wrote:Anyone?? i would think this shouldn't have to be that hard to answer for someone who knows what he's doing..

Thanks!

instead of ls -al use rm

and yes it should work
User avatar
sander
Release Testers
Release Testers
Posts: 8832
Joined: January 22nd, 2008, 2:22 pm

Re: Delete files smaller than XXMB

Post by sander »

solonvault wrote:Anyone?? i would think this shouldn't have to be that hard to answer for someone who knows what he's doing..

Thanks!
My advice to you:

Just execute the command from the command line of your NAS, and see what is does. Try to understand it.

FYI: the command is harmless: with the "ls" (and no "rm") it just list files and directories. It does not delete anything.

As soon as you understand the one-liner, change it the way you like it, and then put it in a script, and only then into SABnzbd.
Post Reply