Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding files modified within an hour of another file

Tags:

linux

find

unix

If i have 3 files called 1.txt,2.txt and 3.txt for example and they were created an hour apart, say 1pm 2pm and 3pm respectively. What I need is a command that finds all files modified within an hour of a specific file.

I'm in the same directory as the files in the terminal and all files are setuid permission

I've been trying:

find . -type f -perm -4000 -newer 2.txt -mmin -60 -print

This should return 3.txt but it doesn't

What would use to file created in the hour before or after 2.txt?

like image 559
Nexus490 Avatar asked Sep 05 '25 03:09

Nexus490


1 Answers

Try this

touch /tmp/temp -t time1

touch /tmp/ntemp -t time2

find . -newer /tmp/temp -a ! -newer /tmp/ntemp -exec ls -l {} \; 2>/dev/null

where

time1 = time of file creation - 1hr

time2 = time of file creation + 1hr

Ex:

time1 = 201210041500

time2 = 201210041700

like image 116
Odin Avatar answered Sep 08 '25 11:09

Odin