2

Im trying to find files on my computer that has been created 1 hour before and 1 hour after a particular file has been created.

This is the method i tried -

find /root -newermt "2012-10-04 1800" -and -newermt "2012-10-04 2000" -exec ls -ldb {} \;

the directory on my linux is root, the particular file created was created at 19:00

this is another method i tried which work but it only displayed one result of after or before not both! >

find /root/Downloads -type f \( -newer /root/Downloads/alex.txt ! -newer /root/Downloads/hesham.txt \)  
Hashey100
  • 994
  • 5
  • 22
  • 47

2 Answers2

2

You want:

# missing a -not here ---------------------v
find /root -newermt "2012-10-04 1800" -and -not -newermt "2012-10-04 2000" -exec ls -ldb {} \;

This does:

  1. all files in /root
  2. that are newer than "2012-10-04 1800"
  3. and that are not newer than "2012-10-04 2000" (or older than "2012-10-04 2000")
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • is there a way that i can pass the file name directly within the `newer` quotation so that i can get the files which have been created after that file which i have given it within the quotes? – Kulasangar Nov 09 '14 at 09:41
1

This may not be the most efficient solution but ..

touch /tmp/temp -t time-of-file-creation-1hr

touch /tmp/ntemp -t time-of-file-creation+1hr

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

Odin
  • 114
  • 1
  • 4