Delete Files Under a Certain File Size

adelgado

Member
Dec 13, 2013
10
0
1
cPanel Access Level
Root Administrator
Hey Everyone, I'm just trying to better understand and find a command i can use as a cron job to delete certain files on my server that are under a certain file size. So i can maintain and keep the server a bit cleaner anyone able to help me with this?

Thanks
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,260
463

adelgado

Member
Dec 13, 2013
10
0
1
cPanel Access Level
Root Administrator
Alright thanks!! I'll take a look at it right now

- - - Updated - - -

So just to make sure i can place this right in cPanel's section "Cron Jobs" with a recurring time to run this find . -size -100k -delete also i read somewhere that cron used rounded of bytes to 512k symbolizing c or n, in this format would it be by straight kilobytes?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,260
463
I do not recommend setting up a cron job to delete all files on your system under that size. You could potentially remove files that are required for accounts, cPanel, or your OS to function as expected. In addition, it's possible to remove data that a customer may require. Are there specific files that you are targeting?

Thank you.
 

adelgado

Member
Dec 13, 2013
10
0
1
cPanel Access Level
Root Administrator
I do not recommend setting up a cron job to delete all files on your system under that size. You could potentially remove files that are required for accounts, cPanel, or your OS to function as expected. In addition, it's possible to remove data that a customer may require. Are there specific files that you are targeting?

Thank you.
I work for a telemarketing company and we store all our recorded calls on the server, the reason for doing this would be to delete all calls that were not intrested or busy whatnot.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,260
463
You may want to instead implement a command that deletes the files based on the name of the file rather than it's size. Or, use a combination of the file name and it's size.

Thank you.
 

adelgado

Member
Dec 13, 2013
10
0
1
cPanel Access Level
Root Administrator
Well the files only get uploaded with the employee's account that made the call phone number and i believe that is it, would there be a way to set it so if it includes 10 numbers in the beginning of the name and is this small then delete it? I just think it would be hard to come up with something for that, but i do see where there would be the issue of losing other things.
 

adelgado

Member
Dec 13, 2013
10
0
1
cPanel Access Level
Root Administrator
Our file names always vary they come from our dialer program with phone dialed, user account that made the call, and time. Is there a way that i can make a command that only delete files if they start with 10 numbers and is under this size??

Thanks
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,260
463
Are all of the files stored in a specific directory?

Thank you.
 

adelgado

Member
Dec 13, 2013
10
0
1
cPanel Access Level
Root Administrator
No the whole server is a bunch of directories with only sound files split up from different sales campaigns and the different departments, but these small files should exist in everywhere directory making things a bit difficult.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,260
463
Well the files only get uploaded with the employee's account that made the call phone number and i believe that is it, would there be a way to set it so if it includes 10 numbers in the beginning of the name and is this small then delete it?
Yes, this should be achievable with a custom bash command. Try using the "find" command on it's own first, and see if you are happy with the output before adding the "rm" command to it.

Thank you.
 

adelgado

Member
Dec 13, 2013
10
0
1
cPanel Access Level
Root Administrator
Alright if you haven't noticed completely new to cPanel, i'm trying to see the find . -size -100k for a test do i have to set it as a cron job or can i just go in to like a normal command prompt.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,260
463
You can enter it in the command prompt as you would any other command to see the results. Once you are happy with the output and actions of the command, you can add it as a root cron job with the following command:

Code:
crontab -e
Thank you.
 

adelgado

Member
Dec 13, 2013
10
0
1
cPanel Access Level
Root Administrator
I didn't see your reply but i ended up finding that got it to work find /home/(directory) -name '*.wav' -size -50k -delete


Thanks again for your help!!
 
Last edited: