delete files leaving current date.
Hi,
am trying make a script that deletes all files just leaving the current day from current the directory
Eg: if today is Nov 30, then should delete all files dated less than Nov 29. i.e 29,28,27,26,25,.....etc
from below examples you can able to see that
-mtime 1 is bringing both 28th and 29th dated files
-mtime +1 is bringing files beyond 28th.
is there any way to get this done by using awk ?
[root@localhost d1]# date
Wed Nov 30 11:46:15 IST 2016
[root@localhost d1]# ls -ltr
drwxr-xr-x. 2 root root 4096 Nov 8 13:06 d2
-rw-r--r--. 1 root root 0 Nov 28 01:01 f34
-rw-r--r--. 1 root root 0 Nov 28 01:01 f3
-rw-r--r--. 1 root root 0 Nov 28 01:01 f1
-rw-r--r--. 1 root root 0 Nov 28 23:01 f6
-rw-r--r--. 1 root root 0 Nov 29 01:01 f5
-rw-r--r--. 1 root root 0 Nov 29 01:01 f4
-rw-r--r--. 1 root root 0 Nov 29 23:01 f7
-rw-r--r--. 1 root root 0 Nov 30 10:23 f2
-rw-r--r--. 1 root root 0 Nov 30 10:24 201611280101.01
-rw-r--r--. 1 root root 75 Nov 30 11:35 qw
[root@localhost d1]# find -type f -mtime 1 -exec ls -ltr {} \;
-rw-r--r--. 1 root root 0 Nov 29 01:01 ./f5
-rw-r--r--. 1 root root 0 Nov 29 01:01 ./f4
-rw-r--r--. 1 root root 0 Nov 28 23:01 ./f6
[root@localhost d1]# find -type f -mtime +1 -exec ls -ltr {} \;
-rw-r--r--. 1 root root 0 Nov 28 01:01 ./f34
-rw-r--r--. 1 root root 0 Nov 28 01:01 ./f3
-rw-r--r--. 1 root root 0 Nov 28 01:01 ./f1
|