Listing files from October 4th is not accurate

Good evening:
Need your help please

Before deleting older logs from octobre 4th i need to identify which files i have to remove, for instance today is octobre 8ht, i need to remove files from October 4th

Because there are many files i can not list because error args too long, so

/produccion/explotacion/xpfactur/facturacion/log/CRMLogs/nociclo # ls|wc -l
500318

Thos is the command:

find ./ -mtime +4 -name "Impres*.log" -type f -exec ls -lrt {} \;|more

output:

rw-r--r--   1 xpfactur explotacion  945067 Sep 25 01:00 ./CRMLogs_11583846.log
-rw-r--r--   1 xpfactur explotacion  927900 Sep 25 01:00 ./CRMLogs_11605696.log
-rw-r--r--   1 xpfactur explotacion  922556 Sep 25 01:00 ./CRMLogs_11591810.log
-rw-r--r--   1 xpfactur explotacion  945192 Sep 25 01:00 ./CRMLogs_11631276.log
-rw-r--r--   1 xpfactur explotacion  922258 Sep 25 01:00 ./CRMLogs_11559556.log

above just list files from september 25th, but files from octuber 4rth really exists when i use this command:

SCEL /produccion/explotacion/xpfactur/facturacion/log/CRMLogs/nociclo # find ./ -name "CRMLogs*" -type f -mtime -7 -exec ls -l {} \;|more
-rw-r--r--   1 xpfactur explotacion  122108 Oct  4 09:45 ./CRMLogs_11824221.log.gz
-rw-r--r--   1 xpfactur explotacion  122149 Oct  4 10:01 ./CRMLogs_11824388.log.gz
-rw-r--r--   1 xpfactur explotacion  122068 Oct  3 11:51 ./CRMLogs_11814440.log.gz
-rw-r--r--   1 xpfactur explotacion  121271 Oct  3 15:25 ./CRMLogs_11817732.log.gz
-rw-r--r--   1 xpfactur explotacion  121857 Oct  3 16:53 ./CRMLogs_11819599.log.gz
-rw-r--r--   1 xpfactur explotacion  122364 Oct  4 11:19 ./CRMLogs_11825342.log.gz
-rw-r--r--   1 xpfactur explotacion  122101 Oct  4 12:07 ./CRMLogs_11826156.log.gz
-rw-r--r--   1 xpfactur explotacion  123191 Oct  4 12:09 ./CRMLogs_11826190.log.gz
-rw-r--r--   1 xpfactur explotacion  123294 Oct  4 12:14 ./CRMLogs_11826738.log.gz
-rw-r--r--   1 xpfactur explotacion  122536 Oct  4 12:18 ./CRMLogs_11827227.log.gz
-rw-r--r--   1 xpfactur explotacion  121686 Oct  4 12:24 ./CRMLogs_11827749.log.gz
-rw-r--r--   1 xpfactur explotacion  122314 Oct  4 12:28 ./CRMLogs_11828380.log.gz
-rw-r--r--   1 xpfactur explotacion  122155 Oct  4 14:29 ./CRMLogs_11830152.log.gz
-rw-r--r--   1 xpfactur explotacion  121209 Oct  4 17:20 ./CRMLogs_11832826.log.gz
-rw-r--r--   1 xpfactur explotacion  122128 Oct  4 18:21 ./CRMLogs_11834403.log.gz
-rw-r--r--   1 xpfactur explotacion  122126 Oct  4 18:21 ./CRMLogs_11834425.log.gz
-rw-r--r--   1 xpfactur explotacion  122357 Oct  4 18:38 ./CRMLogs_11834942.log.gz
-rw-r--r--   1 xpfactur explotacion  122341 Oct  4 18:59 ./CRMLogs_11835504.log.gz
-rw-r--r--   1 xpfactur explotacion  121782 Oct  8 00:28 ./CRMLogs_12031105.log.gz
-rw-r--r--   1 xpfactur explotacion  121780 Oct  8 00:29 ./CRMLogs_12031056.log.gz
-rw-r--r--   1 xpfactur explotacion  121213 Oct  4 23:32 ./CRMLogs_11837553.log.gz
-rw-r--r--   1 xpfactur explotacion  121458 Oct  4 23:36 ./CRMLogs_11838724.log.gz
-rw-r--r--   1 xpfactur explotacion  121468 Oct  4 23:42 ./CRMLogs_11838186.log.gz

how to get around this to list excactly logs from October 4th ?

the opartating system is:

SunOS serber100c 5.10 Generic_144488-01 sun4u sparc SUNW,SPARC-Enterprise

I appreciate your help in advanced

Assuming that you don't need to descend into a file hierarchy and just want to process files in your current working directory, a couple of obvious choices would be:

ls -l | grep 'CRMLogs' | grep 'Oct  4'

and:

ls -l | /usr/xpg4/bin/awk '$6 == "Oct" && $7 == "4" && $9 ~ "CRMLogs"'

If you do need to descend into the file hierarchy rooted in your current working directory, you could also try:

#!/bin/ksh
ls -lR | /usr/xpg4/bin/awk '
$1 ~ ":$" {
	dir = substr($1, 1, length($1) - 1) "/"
	next
}
$6 == "Oct" && $7 == 4 && $9 ~ /CRMLogs/ {
	print dir $9
}'

This code assumes that none of your filenames contain any whitespace characters.

3 Likes

thanks you very much, there is no file hierarchy , there are no subfolders so the 1st choice applies.

Identifying files from october 4th i assume i have to script to delete or compress these files right ?

because the purpose of using the find command gives me the pipeline facility and delete and log the removed files at once

I appreciate your help in advanced

You don't mention your OS, shell, nor find versions. Should you have bash (I think the "%(%s)T" format works in other shells as well), and GNU find , you could try

BEG=$(printf "%s\n" $(( ( $(printf "%(%s)T") - $(date +"%s" -d"oct 4")) / 60 ))); END=$((BEG-1440)); find . -maxdepth 1 -mmin -$BEG \! -mmin -$END -ls -delete

Thanks again. Regarding the OPerating System is:

SunOS serber100c 5.10 Generic_144488-01 sun4u sparc SUNW,SPARC-Enterprise

So the above solution works for this environment and operating system?

Hi. No, RudiC's suggestion does not work with Solaris 10.

1 Like