Hi,
I need files exactly 3 to 7 days old.
Today is 28th July 2016.
I have two files one dated 25th July and other 21st July which are 3 to 7 days old.
94702 1 -rw-r--r-- 1 m1083 user1 26 Jul 25 13:00 ./Report_0751.txt
94751 1 -rw-r--r-- 1 m1083 user1 128 Jul 21 13:00 ./Report_0710.txt
Below is what i tried
find . -mtime +2 -a -mtime -7 -ls
But instead of displaying both the files it shows only one file dated 21st.
My understanding of the command is-> find files more than 2 days old and not more than 7 days old -> which means both the files dated 25th and 21st.
Can you please tell me why i dont see both the files as output of the find
command ?
Moto: I will use the same solution to find files exactly 7 days old.
At what time of day did you search for files less than 7 days old? (Was it before or after the 1pm timestamp on both of your files?)
find command does NOT use calendar days.
$ date
Thu, Jul 28, 2016 8:30:10 PM
$ date +%s
1469759421 # this NOW on my computer, the number of seconds since midnight on Jan 1 1970.
1469759421 -86400 =1469673021 # this is one day ago. It is 8:30 yesterday evening.
This is how find works.
One way to get calendar days is to create two dummy files
use the touch command NOTE: I am using the date on my system, you make it fit yours:
touch -t 201607210000 dummy1 # seven days ago at the very start of the day
touch -t 201607252359 dummy2 # three days ago at the END of the day i.e., 23:59
find /path/to/files -type f - \( -newer dummy1 -a !-newer dummy2 \)
I would consider making two dummy files to set the start and end date/times that you are interested in and then use the -newer
flag of find to search between them.
I hope that this helps,
Robin
-mtime 7
means the files that are between 7*24*6060 seconds and 8*24*6060 seconds old.
If you want a certain calendar day then you must run this at midnight.
1 Like