How to make a script for deleting files under X size?

Discussion in 'Mac Basics and Help' started by HarryPot, Oct 7, 2013.

  1. HarryPot macrumors 6502a

    Joined:
    Sep 5, 2009
    #1
    I'm trying to make a script that automatically delete files under 10mb in a folder.

    Is this possible?


    Thanks in advance.:)
     
  2. mfram macrumors 65816

    Joined:
    Jan 23, 2010
    Location:
    San Diego, CA USA
    #2
    Using the Unix shell. Use Terminal:

    To print the files that will be caught:
    Code:
    find directory -maxdepth 1 -size -10M -type f -print
    To actually delete them:
    Code:
    find directory -maxdepth 1 -size -10M -type f -delete
    Replace "directory" with the directory name in both cases. That command will only delete the files in that directory. Take out the "-maxdepth 1" if you want it to recurse down all directories in that tree.
     
  3. HarryPot thread starter macrumors 6502a

    Joined:
    Sep 5, 2009
    #3
    Thanks! I'll give it a try today.
     
  4. HarryPot thread starter macrumors 6502a

    Joined:
    Sep 5, 2009
    #4
    Ok, it seems that the code only works in Terminal, not in AppleScript.

    Is there a similar code that works in AppleScript?
     
  5. MacUser2525 macrumors 68000

    MacUser2525

    Joined:
    Mar 17, 2007
    Location:
    Canada
    #5
    Well use some other script capable method like a bash script in combination with a cron job to do the automatic deletions by calling your script at per-determined times.
     

Share This Page