[bash] Seeing if a file has been modified before/after a date
I can't seem to figure this simple thing out. There's this folder and stuff will be put inside of it. I want to find out if it was moved there after a certain day and time which are in the format, mm/dd/yy and hh:mm, although I can probably change the format. BTW, this is in Bash. I think I need to use ls -l --time-style="+%D %R" and then extract those two fields and compare that with the given date and time. I think I'm making this harder than it is. Can anyone help me out here? Can I use Date somehow? Thanks.
|
I hate doing this, but man find ... I believe there is probably something there that will suit your needs.
|
Find is an alternative, but it assumes you already know the date you are looking for.
What I do is simple and dumb. I translate every time stamp into seconds using the date command, and then perform arithmetic with it. If you want to know the date/time of a file, use the correct modifiers with the ls command, awk the fields what you want. Feed this into date and convert it to seconds. jlinkels |
info find is generally more useful, I found this:
Quote:
Code:
touch --date='mm/dd/yy hh:mm' /tmp/stamp$$ |
Quote:
|
Hi.
If what you truly want is: Quote:
Code:
"When we are talking about file times we refer to three unix However, there may be a way to approximate the time. Because you moved something into a directory, and a directory is a special kind of file, the mtime of the directory would reflect the last time a change occurred there. The mtimes of the source and target directories would be the important times. If the files were moved into the directory at the same time, and if you made no subsequent changes to the directory, the time of the directory modification would be (about) the time of the move. See man ls for details on listing the different times of the directory, but it would look something like: Code:
ls -ld directory-path Another possibility is if you created the files and moved them shortly afterward into the directory and made no other changes to the files, then the mtime of the files would be close to when you moved them. Best wishes ... cheers, makyo ( edit 1: clarify ) |
On that note: Tripwire or AIDE should help with these kinds of tasks.
Cheers, Tink |
Well I don't know if this changes things, but what I'll be doing is creating a tar and putting some files in it when I specify (could be any time any day) and then moving it onto that folder, upon which I'll compare the dates.
Example, my brother will specify some files, I'll TAR them and then move them onto the folder. I'll then compare if it's before or after a date. |
All times are GMT -5. The time now is 08:19 PM. |