Cron to delete particular file(s) from a specific directory

66

Solution 1

Try the find command.

find /somedir1/somedir2 -name *.txt -name *.log -mtime 2w -delete

Change -delete to -print for a dry run.

Solution 2

You could also leverage tmpwatch http://linux.die.net/man/8/tmpwatch, using whichever parameters of atime, ctime, or mtime suit your needs.

For example, tmpwatch --atime 30d /foo will remove all files in /foo that haven't been accessed in 30 days.

Share:
66

Related videos on Youtube

user278618
Author by

user278618

Updated on September 18, 2022

Comments

  • user278618
    user278618 over 1 year

    I have class StatusesInvestmentRow (from dataSource) where one of the field is ModifiedDate

    Investment table:
    
    Id int PK;
    ModifiedDate datetime;
    

    How can I sort this arrayby this date?

    I found example with IComparable but StatusesInvestmentRow has DataRow type so it is not good way I think.

    I have this and I can't change this:

      statInw = new GetAllInvestmentStatuses();
    

    I want add something like:

      var newestStatusInvestment = statInv.Sort(comparerByDate)[0];
    
    • Mikel
      Mikel over 11 years
      The find command does everything you need. man find
  • Paul Sasik
    Paul Sasik over 13 years
    Those select functions return DataRow[]