Deleting files bigger then 20 MB

Discussion in 'Site & Server Administration' started by mycomputerguide, Mar 3, 2009.

  1. #1
    I want to delete all files that are bigger then 20MB in a folder called /var/www/cg/

    I found this on google:

    find / -size +2000000c 2>/dev/null -exec ls -l {} \;

    I ran it in the directory /var/www/cg/ and thought it would only delete the files in the current directory but it didn't :( it deleted every file on the server bigger then 20 MB so I skipped it as fast as possible...

    Can someone tell me how to delete files bigger then 20MB only in that certain directory?
     
    mycomputerguide, Mar 3, 2009 IP
  2. tolra

    tolra Active Member

    Messages:
    515
    Likes Received:
    36
    Best Answers:
    1
    Trophy Points:
    80
    #2
    find /var/www/cg/ -size +20M -exec ls -l {} \;
    Code (markup):
    That should list all the files over 20M
    find /var/www/cg/ -size +20M -exec rm -f {} \;
    Code (markup):
    That should delete them, no confirmation is given.
     
    tolra, Mar 3, 2009 IP
  3. mycomputerguide

    mycomputerguide Peon

    Messages:
    71
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks a lot Tolra!
     
    mycomputerguide, Mar 3, 2009 IP