Del files older than today

Hi all,
I have the following line in my script I need to delete all files that were not created today.

find . -type f -name '*.trm' -mmmin +1440 -exec rm {} \;

or

find . -type f -name '*.trm' -mtime +2 -exec rm {} \;

The issue is that we are still seeing files older than today.

Thanks for any help

@tcpip, welcome to the forums.
I've edited your post using proper markdown tags for your code samples. Please make sure you make the properly formatted posts!

1 Like

Found the solution

find . -type f -name '*.trm' -mtime 1 -exec rm {} \;

-mtime 1 means 24...48 hours old.
-mtime +0 means 24 hours or older.

Hello

What I need is to delete all files from yestarday in this case I need to delete all files from the 22th.

find . -type -f ls |grep 'Jun 22' |  wc -l

I get 600 files
I I use

find . -type f -name '*.trm' -mtime +0 

I get 514 files, I dont know where the rest of the files are.

thanks.

find . -type -f ls |grep 'Jun 22' |  wc -l

this is wrong: -type -f ls
what does the following give you?

find . -type f -name '*.trm' -ls |grep 'Jun 22' |  wc -l

Also -atime/-mtime are relative specs - relative to the time of the execution.
From man find:

       -mtime n
              File's  data was last modified n*24 hours ago.  See the comments
              for -atime to understand how rounding affects the interpretation
              of file modification times.

       -atime n
              File  was  last  accessed n*24 hours ago.  When find figures out
              how many 24-hour periods ago the file  was  last  accessed,  any
              fractional part is ignored, so to match -atime +1, a file has to
              have been accessed at least two days ago.

also

       find $HOME -mtime 0

       Search for files in your home directory which have been modified in the
       last twenty-four hours.  This command works this way because  the  time
       since  each  file  was last modified is divided by 24 hours and any re‐
       mainder is discarded.  That means that to match -mtime 0, a  file  will
       have  to  have  a  modification in the past which is less than 24 hours
       ago.

So you're not really comparing apples to apples...
If you want to identify the differences... instead of ...| wc -l spool both commands to files and find the differences (a file exists in one listing and not the other and vice versa) to see how the listings differ - this can easily be done with awk.

HI ,

Thanks for all your help, the big issue is the lack of know how. but I will keep searching.

thanks

1 Like

-daystart -mtime 1 means from yesterday
-daystart -mtime +0 means from yesterday or older.
GNU find required.

1 Like

I did all the +0 option but when I search but date I still have find files older than the actual date.

Thanks.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.