Page 1 of 2
Delete files smaller than XXMB
Posted: July 6th, 2012, 4:58 am
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!!
Re: Delete files smaller than XXMB
Posted: July 6th, 2012, 10:12 pm
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.
Re: Delete files smaller than XXMB
Posted: July 15th, 2012, 1:51 pm
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 !!
Re: Delete files smaller than XXMB
Posted: July 15th, 2012, 1:55 pm
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?
Re: Delete files smaller than XXMB
Posted: July 15th, 2012, 3:04 pm
by exussum
find -size -500k -exec rm {\}\ \;
maybe ?
Re: Delete files smaller than XXMB
Posted: July 15th, 2012, 3:24 pm
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?
Re: Delete files smaller than XXMB
Posted: July 15th, 2012, 3:36 pm
by exussum
I remember having to escape more, I should learn to try commands before posting
Your way is better than mine - Looking for files too (mine could pick up directory's / links)
Re: Delete files smaller than XXMB
Posted: July 15th, 2012, 3:59 pm
by sander
exussum wrote:I remember having to escape more, I should learn to try commands before posting
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.
Re: Delete files smaller than XXMB
Posted: July 16th, 2012, 1:16 am
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!
Re: Delete files smaller than XXMB
Posted: July 16th, 2012, 1:22 am
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 ...
Re: Delete files smaller than XXMB
Posted: July 16th, 2012, 1:24 am
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
Re: Delete files smaller than XXMB
Posted: July 16th, 2012, 10:02 am
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!
Re: Delete files smaller than XXMB
Posted: July 17th, 2012, 3:35 pm
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!
Re: Delete files smaller than XXMB
Posted: July 17th, 2012, 4:03 pm
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
Re: Delete files smaller than XXMB
Posted: July 17th, 2012, 4:22 pm
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.