Find files modified in previous minute only

Hi,

How can I get files which are modified only in last minute ? it should not display 2 minutes back file

ls -la 

-rw-rw-r-- 1 stuser st  51 Dec  3 09:22 a.csv
-rw-rw-r-- 1 stiser st  50 Dec  3 09:25 b.csv
-rw-rw-r-- 1 stuser st  53 Dec  3 09:33 c.csv

When I run command at 9:34am then I should see only 9:33am file and not remaining 2 files because those were modified before 9:33am

Thanks

One way would be to create a reference file with a timestamp to look back to. If you run it at 09:34 on 3rd December 2014, and you need to find files newer that 09:33:00 then you can (working out the values of course):-

touch -mt 201412030934 /tmp/ref_file
find . -newer /tmp/ref_file

The format value is in the manual page for the touch command.

If you need to include the seconds to get a more accurate 'previous minute' then simply add the seconds part, e.g.:-

touch -mt 201412030934.22 /tmp/ref_file
find . -newer /tmp/ref_file

If you have support for the -d flag, then you could do this:-

touch -md "1 minute ago" /tmp/ref_file
find . -newer /tmp/ref_file

I hope that this helps,
Robin

1 Like

If you want the clock minute only, use two marker files, one touched to prior minute:00 and the second to current minute:00, and "find . . . -newer f1 ! -newer f2", possibly with an escape on the ! = \!. Thus, you get a 60 second snapshot of one specific clock minute. This is more useful statistically, else the set may reflect 61 to 119 seconds.

1 Like

hi batte,
thanks for the solution. it worked. but i have 2 questions in that

1) how can i get files display with date and bytes information just like how it displays when we issue ls -la ?

2) what if i want to give minutes range to get files ?

ex: Want to display all the files between 201412030930 to 201412031230 ?

Sorry that i extended the question scope

Appreciate

You have a way to get the list of files, so you have several options depending on what find supports:-

  • Add a section -exec ls -l {} \+
  • Add a section -exec ls -l {} \; which is slower than the above but sure to be available
  • Add another command the end find ...... | xargs ls -l

To get files by a range of minutes, DGPickett has already given you the tools to do this, but you were probably typing your reply when that was submitted.

There are probably plenty of other ways too. Do any of these appeal?

Robin

Thanks

between dates working in this way

touch -t 201412031400 first && touch -t 201412031459 last && find / -newer first ! -newer last

appreciate for your answers

And to get the output in the same format as the output from ls -la , try:

touch -t 201412031400 first && touch -t 201412031459 last && find / -newer first ! -newer last -exec ls -ld '{}' +

or, if you only want regular files to be included in the output:

touch -t 201412031400 first && touch -t 201412031459 last && find / -type f -newer first ! -newer last -exec ls -l '{}' +

Wait, that's 59 seconds, not a minute.

Also, if you use the current time, you are fractionally though this second, so sleep a second to let a full second be included.