You cannot change the ctime by ordinary means. This is by design: the ctime is always updated to the current when you change any of the file's metadata, and there is no way to impose a different ctime. To change the ctime of a file, you need to do one of the following:
- Set the system time to the ctime you want to impose, then touch the file, then reset the system time.
- Modify the kernel to add an interface to change the ctime.
- Access the disk image directly (e.g. with
debugfs
) and twiddle the bits on the disk (don't do it while the filesystem is mounted).
You can easily get that information using stat
. As for ancestral directories, it is easily checked that if a file changes that this doesn't affect anything "up the hierarchy" by looking at /
:
root@pooh:/home/anthon-mint# stat /
File: ‘/’
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 804h/2052d Inode: 2 Links: 30
Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2015-02-22 09:57:14.028146463 +0100
Modify: 2015-01-01 10:34:05.528461374 +0100
Change: 2015-01-01 10:34:05.528461374 +0100
Birth: -
as the system is constantly changing files, these values should be close to the current time.
If you create a new directory, and then a file in it, access and modification time of the directory change:
$ mkdir tmp
$ stat tmp
File: ‘tmp’
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 700h/1792d Inode: 144141 Links: 2
Access: (0775/drwxrwxr-x) Uid: ( 1001/ anthon) Gid: ( 100/ users)
Access: 2015-02-27 16:19:02.523585508 +0100
Modify: 2015-02-27 16:19:02.523585508 +0100
Change: 2015-02-27 16:19:02.523585508 +0100
Birth: -
$ touch tmp/bla
$ stat tmp
File: ‘tmp’
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 700h/1792d Inode: 144141 Links: 2
Access: (0775/drwxrwxr-x) Uid: ( 1001/ anthon) Gid: ( 100/ users)
Access: 2015-02-27 16:19:02.523585508 +0100
Modify: 2015-02-27 16:19:18.639585445 +0100
Change: 2015-02-27 16:19:18.639585445 +0100
Birth: -
Access time doesn't change, but the creation of the new file changes modification and change time.
Now touch the file again:
$ touch tmp/bla
$ stat tmp
File: ‘tmp’
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 700h/1792d Inode: 144141 Links: 2
Access: (0775/drwxrwxr-x) Uid: ( 1001/ anthon) Gid: ( 100/ users)
Access: 2015-02-27 16:19:02.523585508 +0100
Modify: 2015-02-27 16:19:18.639585445 +0100
Change: 2015-02-27 16:19:18.639585445 +0100
Birth: -
$
And the directory doesn't change, but none of the information for the directory changes, as no new file is created.
Changing the mtime, atime, or ctime of an existing file has no effect on the directory it is in, nor on any of that directory's parents.
Best Answer
When you run
emacs
it creates a backup file, int his casetest.txt~
. If there was already a file with that name I suspect it deletes it and creates a new one. That new file creation is modifying the directory, and thus updating its modified and changed times.If you were, instead, to say
echo new line >> blah.txt
you would not be creating any extra files, and so would not update those entries on the directory. In this case, the shell just opens the file (for append).