bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mv changes timestamp


From: Jim Meyering
Subject: Re: mv changes timestamp
Date: Fri Nov 22 04:13:02 2002

Francesco Tarantelli <address@hidden> wrote:
> mv from fileutils-4.1.tar.gz, recompiled con RedHat Linux 7.3 (intel)
> (as well as the one distributed in fileutils-4.1-10.i386.rpm)
> changes the timestamp of directories when moving them. Is this the
> intended behavior?

Whether mv'ing (via kernel `rename') a directory changes the
timestamp of that directory is system dependent.  For some file system
implementations, it does change, and for others it does not.  I've heard
it argued both ways.  The update-timestamp camp argues that when a
directory's `..' link is changed, that merits an update.  That might
mean that a simple name change would not result in an updated date,
while a change in hierarchy would.  People have argued that as part of
the rename, the directory is `link'd and `unlink'd behind the scenes,
and those operations do modify the directory.

Here are some commands to demonstrate the behavior of
your favorite OS/filesystem combinations:

  mkdir j
  stat -c '%X %Y %Z' j; sleep 2
  mv j j2
  stat -c '%X %Y %Z' j2; sleep 2
  mkdir d
  mv j2 d
  stat -c '%X %Y %Z' d/j2

When running the above on linux-2.4.18 using ext3, all of the
resulting access and modification times were the same.
Likewise for tmpfs.

Note that the third number on each line (`change' time, aka ctime)
is expected to change.

I'm pretty sure a version of Linux from not too far back
did have an implementation of rename that changed directory
time stamps for some file system type.  Maybe all you need
is a newer kernel.

Jim
-----------
P.S., if you don't have stat, you can use perl, e.g.:

  mkdir j
  perl -MFile::stat -e 'my $s = stat "j" or die;\
    print $s->mtime," ",$s->atime," ",$s->ctime,"\n"'; sleep 2
  mv j j2
  perl -MFile::stat -e 'my $s = stat "j2" or die; \
    print $s->mtime," ",$s->atime," ",$s->ctime,"\n"'; sleep 2
  mkdir d
  mv j2 d
  perl -MFile::stat -e 'my $s = stat "d/j2" or die; \
    print $s->mtime," ",$s->atime," ",$s->ctime,"\n"'

You can find the latest test release here:
  ftp://alpha.gnu.org/gnu/fetish/coreutils-4.5.3.tar.gz




reply via email to

[Prev in Thread] Current Thread [Next in Thread]