2

I want to get every files that are between 2 date with this format : YYYY-MM-DD HH:mm

I have some constraints too : i can't write files even in /tmp, and i can't use find --newermt because it's an old server.

I tried to use awk without success :

ls -l  --time-style=long-iso | awk '{ if (mktime(gensub ("-", " ", $6) " " gensub (":", " ", $7) " 00") >= mktime(gensub ("-", " ", gensub (":", " ", "2014-08-26 12:30")) " 00") && mktime(gensub ("-", " ", $6) " " gensub (":", " ", $7) " 00") <= mktime(gensub ("-", " ", gensub (":", " ", "2014-08-26 12:30")) " 00")) print $8 }'

Thanks in advance !

Paul Le Corre
  • 68
  • 1
  • 5

2 Answers2

2

Do you mean that there is an old version of 'find' or that you don't have 'find' at all.

If you do have find, but it's an old version, then there's another way than '-newermt':

How to use 'find' to search for files created on a specific date?

The third answer shows how to create two files with the timestamps you require. Then use:

find / -newer /tmp/t1 -and -not -newer /tmp/t2
Community
  • 1
  • 1
Daniel Scott
  • 7,418
  • 5
  • 39
  • 58
  • I have an old version of find. But i can't write files because i have only readings rights. It's a prod server in a big company so i can't make what i want :/ – Paul Le Corre Aug 26 '14 at 15:58
2

I'd see if you can use stat with an appropriate format. On my (linux) system, print out the file name and the mtime with

stat --format=$'%n\t%y' *

Then, to filter based on the mtime:

stat --format=$'%n\t%y' * |
awk -F"\t" -v from="2014-08-01 00:00" \
           -v to="2014-09-01 00:00"   'from <= $NF && $NF <= to {NF--; print}'
glenn jackman
  • 238,783
  • 38
  • 220
  • 352