finding files n mins older or newer then a specific file
Hey!
I was wondering if it was possible to find files created, accessed or modified 30 mins before a specific file was created, access or modified using shell commands. e.g I find a file that was created on my system yesterday at 10am, I now want to find all files that were created between 9:30am and 10am, is this possible? Thanks |
Well, this works for dates (days)
Code:
find . -mtime +1 -and -mtime -30 -print |
In a nutshell, yes. Though, the way you phrased your question leaves some ambiguity as to exactly what you want.
First, the find command can filter files based modification, status change, and access: Code:
-amin n Further, find allows you to combine the options using logical AND and OR conditions. A logical AND is applied to sequential options by default. So it is possible for you to do something such as: Code:
-amin -31 -amin +1 The man page for find (man find) also states that these comparisons are based on the values from stat. You can run stat manually on a particular file: Code:
stat somefilename Code:
stat --printf="%X\n" somefilename To tie it all together, you could write a script that: 1. Execute a stat on your reference file and stores the access, status change, and modification time for your reference file 2. Execute date with a date string to get the current number of seconds since the Epoch 3. Store for each access/status/modification time the from date minus the value for that particular time received from stat 4. Add an amount of seconds to each equal to the outer limit of your test (30 minutes in this case = 1800 seconds) 5. Convert the seconds into minutes by dividing with 60 6. Calculate your inner limit for each time (the original times returned by stat in this case), but converted to minutes 7. Construct your find command with those values. For instance: Code:
find / -amin -<outer limit access> -amin +<inner limit access> -cmin -<outer limit status change> -cmin +<inner limit status change> -mmin -<outer limit modification> -mmin +<inner limit modification> The ambiguity I mentioned to begin with is because you don't specify whether you want to treat each specific time type (access, status, modification) separately (as I have done in the above example) or if you want to use the earliest value among the three. EDIT: A bash script doing what I described above might be: Code:
#!/bin/bash Lastly, it will only print the rough equivalent of a find command for you--not execute it. The script could be modified to do so, but I have no idea what other restrictions or tests you would want to add. |
Here are a couple of useful links about using find:
http://mywiki.wooledge.org/UsingFind http://www.grymoire.com/Unix/Find.html |
All times are GMT -5. The time now is 04:36 AM. |