The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Delete Files Under a Certain File Size

Discussion in 'General Discussion' started by adelgado, Dec 13, 2013.

  1. adelgado

    adelgado Member

    Joined:
    Dec 13, 2013
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    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
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
  3. adelgado

    adelgado Member

    Joined:
    Dec 13, 2013
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    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?
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    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.
     
  5. adelgado

    adelgado Member

    Joined:
    Dec 13, 2013
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    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.
     
  6. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    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.
     
  7. adelgado

    adelgado Member

    Joined:
    Dec 13, 2013
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    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.
     
  8. adelgado

    adelgado Member

    Joined:
    Dec 13, 2013
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    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
     
  9. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
  10. adelgado

    adelgado Member

    Joined:
    Dec 13, 2013
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    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.
     
  11. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    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.
     
  12. adelgado

    adelgado Member

    Joined:
    Dec 13, 2013
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    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.
     
  13. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    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.
     
  14. adelgado

    adelgado Member

    Joined:
    Dec 13, 2013
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    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?
     
  15. adelgado

    adelgado Member

    Joined:
    Dec 13, 2013
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    I am taking the assumption that -type will cause it to look for that but would a wave file be "w"??

    Thanks
     
  16. LDHosting

    LDHosting Well-Known Member

    Joined:
    Jan 19, 2008
    Messages:
    93
    Likes Received:
    2
    Trophy Points:
    8
    cPanel Access Level:
    Root Administrator
    -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"
     
  17. adelgado

    adelgado Member

    Joined:
    Dec 13, 2013
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    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!!
     
    #17 adelgado, Dec 16, 2013
    Last edited: Dec 16, 2013
Loading...

Share This Page