Delete Files Under a Certain File Size
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
-
Hello :) There is an external thread on another website discussing this at: [url=http://stackoverflow.com/questions/5057041/linux-how-to-get-all-the-files-exceeding-certain-size-and-deleting-them]delete - Linux - How to get all the files exceeding certain size and deleting them - Stack Overflow It mentions files exceeding a certain size, but you can modify this to files under a certain size. Thank you. 0 -
Alright thanks!! I'll take a look at it right now [COLOR="silver">- - - 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? 0 -
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. 0 -
[quote="cPanelMichael, post: 1528861">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.0 -
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. 0 -
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. 0 -
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 0 -
Are all of the files stored in a specific directory? Thank you. 0 -
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. 0 -
[quote="adelgado, post: 1528882">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.0 -
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. 0 -
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: crontab -e
Thank you.0 -
I did a few tests and as you said getting files that i don't want back in the search. Is there a way to add file type to the search? 0 -
I am taking the assumption that -type will cause it to look for that but would a wave file be "w"?? Thanks 0 -
-type will allow you to search for either files or directories specifically. If by file type you mean extension, you could try using the -name switch. For example -name "*.wav" 0 -
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!! 0
Please sign in to leave a comment.
Comments
16 comments