| Author |
Message |
Dave Farrance *nix forums Guru Wannabe
Joined: 21 Feb 2005
Posts: 294
|
Posted: Tue Jul 11, 2006 9:58 pm Post subject:
Re: File timestamp passed by variable?
|
|
|
"Chris F.A. Johnson" <cfajohnson@gmail.com> wrote:
| Quote: | On 2006-07-11, Dave Farrance wrote:
"Chris F.A. Johnson" <cfajohnson@gmail.com> wrote:
fdate=$(stat -c %Y FILE)
touch -d "${fdate%.*}" FILE
Sorry, I meant:
fdate=$(stat -c %y FILE)
|
That works. Neat.
| Quote: | OK, never mind, I've found another way around my original problem.
Which is?
|
Well, I'm embarrassed to admit that rebooting my PC solved the problem
of the ramdisk file that would mysteriously disappear after a few
minutes. I'd assumed that I had a bug in my script that was doing it,
but I guess that it must have been a random corruption of the ramdisk
structure.
--
Dave Farrance |
|
| Back to top |
|
 |
Chris F.A. Johnson *nix forums Guru
Joined: 20 Feb 2005
Posts: 2268
|
Posted: Tue Jul 11, 2006 9:42 pm Post subject:
Re: File timestamp passed by variable?
|
|
|
On 2006-07-11, Dave Farrance wrote:
| Quote: | "Chris F.A. Johnson" <cfajohnson@gmail.com> wrote:
Dave Farrance <DaveFarrance@OMiTTHiSyahooANDTHiS.co.uk> writes:
Is it possible to get the timestamp of a file with "stat", save it in a
variable, and then apply that date with "touch" to another file?
You can use stat if you like. GNU/Linux:
fdate=$(stat -c %Y FILE)
touch -d "${fdate%.*}" FILE
That gives the seconds since Epoch, but touch doesn't seem to accept
that date format.
|
Sorry, I meant:
fdate=$(stat -c %y FILE)
(See the stat man page.)
| Quote: | OK, never mind, I've found another way around my original problem.
|
Which is?
--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence |
|
| Back to top |
|
 |
Dave Farrance *nix forums Guru Wannabe
Joined: 21 Feb 2005
Posts: 294
|
Posted: Tue Jul 11, 2006 8:31 pm Post subject:
Re: File timestamp passed by variable?
|
|
|
"Chris F.A. Johnson" <cfajohnson@gmail.com> wrote:
| Quote: | Dave Farrance <DaveFarrance@OMiTTHiSyahooANDTHiS.co.uk> writes:
Is it possible to get the timestamp of a file with "stat", save it in a
variable, and then apply that date with "touch" to another file?
You can use stat if you like. GNU/Linux:
fdate=$(stat -c %Y FILE)
touch -d "${fdate%.*}" FILE
|
That gives the seconds since Epoch, but touch doesn't seem to accept
that date format.
OK, never mind, I've found another way around my original problem.
--
Dave Farrance |
|
| Back to top |
|
 |
Chris F.A. Johnson *nix forums Guru
Joined: 20 Feb 2005
Posts: 2268
|
Posted: Tue Jul 11, 2006 7:00 pm Post subject:
Re: File timestamp passed by variable?
|
|
|
On 2006-07-11, Dave Farrance wrote:
| Quote: | Casper H.S. Dik <Casper.Dik@Sun.COM> wrote:
Dave Farrance <DaveFarrance@OMiTTHiSyahooANDTHiS.co.uk> writes:
Is it possible to get the timestamp of a file with "stat", save it in a
variable, and then apply that date with "touch" to another file?
I've puzzled over the date formats of the two commands and there
doesn't seem to be a common format between them.
touch -r oldfile newfile
Yes, however... I'm trying to trace the reason for a repetitive disk
access, so while the test is running, I want to avoid disk accesses
from the test script. I'm using a file in a ram-disk for a time
reference for the "find" command, but due to some sort of bug, the
ramdisk file keeps disappearing. So in order to trace *that* fault, I
was hoping for a way to store a timestamp in an environment variable,
and re-apply it to a file later on. Oh well, I'll find another way
around the problem.
|
You can use stat if you like. GNU/Linux:
fdate=$(stat -c %Y FILE)
touch -d "${fdate%.*}" FILE
With the BSD stat it's a little more complicated, as you need to
convert seconds since the epoch.
--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence |
|
| Back to top |
|
 |
Dave Farrance *nix forums Guru Wannabe
Joined: 21 Feb 2005
Posts: 294
|
Posted: Tue Jul 11, 2006 6:36 pm Post subject:
Re: File timestamp passed by variable?
|
|
|
Casper H.S. Dik <Casper.Dik@Sun.COM> wrote:
| Quote: | Dave Farrance <DaveFarrance@OMiTTHiSyahooANDTHiS.co.uk> writes:
Is it possible to get the timestamp of a file with "stat", save it in a
variable, and then apply that date with "touch" to another file?
I've puzzled over the date formats of the two commands and there
doesn't seem to be a common format between them.
touch -r oldfile newfile
|
Yes, however... I'm trying to trace the reason for a repetitive disk
access, so while the test is running, I want to avoid disk accesses
from the test script. I'm using a file in a ram-disk for a time
reference for the "find" command, but due to some sort of bug, the
ramdisk file keeps disappearing. So in order to trace *that* fault, I
was hoping for a way to store a timestamp in an environment variable,
and re-apply it to a file later on. Oh well, I'll find another way
around the problem.
--
Dave Farrance |
|
| Back to top |
|
 |
Casper H.S. Dik *nix forums Guru
Joined: 20 Feb 2005
Posts: 1634
|
Posted: Tue Jul 11, 2006 5:44 pm Post subject:
Re: File timestamp passed by variable?
|
|
|
Dave Farrance <DaveFarrance@OMiTTHiSyahooANDTHiS.co.uk> writes:
| Quote: | Is it possible to get the timestamp of a file with "stat", save it in a
variable, and then apply that date with "touch" to another file?
I've puzzled over the date formats of the two commands and there
doesn't seem to be a common format between them.
|
touch -r oldfile newfile
Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth. |
|
| Back to top |
|
 |
Dave Farrance *nix forums Guru Wannabe
Joined: 21 Feb 2005
Posts: 294
|
Posted: Tue Jul 11, 2006 5:24 pm Post subject:
File timestamp passed by variable?
|
|
|
Is it possible to get the timestamp of a file with "stat", save it in a
variable, and then apply that date with "touch" to another file?
I've puzzled over the date formats of the two commands and there
doesn't seem to be a common format between them.
--
Dave Farrance |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|