Find the answer to your Linux question:
Results 1 to 3 of 3
Hi All, I have a huge folder of around 50G in size and have different subdirectories. I want to create a script that can find the files older than different ...
  1. #1
    Just Joined!
    Join Date
    Jan 2008
    Posts
    49

    help - script to delete the files

    Hi All,



    I have a huge folder of around 50G in size and have different subdirectories. I want to create a script that can find the files older than different dates for some of the subdirectories and delete the files.



    I assume to exclude the subdirectory-1 and subdirectory-2 from the following command and delete all files older then 15 days for all other subdirectories.



    find /../rootdirectory/ -type f -daystart -mtime +15 -not -path '/rootdirectory/subdirectory-1/' -not -path '/rootdirectory/subdirectory-1/' -not -path -exec rm {} \;



    find /../rootdirectory/subdirectory-1/ -type f -daystart -mtime +30 -exec rm {} \;

    find /../rootdirectory/subdirectory-2/ -type f -daystart -mtime +60 -exec rm {} \;




    Well this is not working for me



    If someone can suggest some otherway to do this I would really appreciate.



    Many thanks.

  2. #2
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Location
    Tokyo, Japan
    Posts
    858
    for excluding folders you can use prune.
    have a look at the find man page
    Linux and me it's a love story

  3. #3
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    What is not working for you? Is it a syntax error? Is it deleting things from the subdirectories that it shouldn't be? Is it not deleting anything?

    The -path directive is going to try to match against the entire pathname. So it is going to see "/rootdirectory/subdirectory-1/foo" and see if it is "/rootdirectory/subdirectory-1". It is not, so it will try to delete this.

    Try using:
    Code:
    -not -path /rootdirectory/subdirectory-1/'*'
    Note the single quotes around the *: you need to be sure that the shell doesn't try to interpolate the asterisk itself.
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...