Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to change the file modification time without changing the file acess time?

share|improve this question

I found a way. I used GNU stat (stat (GNU coreutils) 8.19) to look at "Access", "Modify" and "Change" timestamps of a file.

I could update the "Change" time by doing a chmod u+x on the file. "Modify" and "Access" timestamps remained the same.

I could update "Access" file by doing a cat on it. "Modify" and "Change" timestamps remained the same.

I wrote a small C program that just does an open(filename, O_WRONLY);, writes a single byte to the file descriptor, and then a close(filedes); on the resulting file descriptor. stat showed no change on the subject file's "Access" timestamp, but "Modify" and "Change" timestamps got updated.

This was all under Linux 3.5.4, a fairly recently update Arch Linux laptop, on an Ext4 filesystem.

The small C program:

#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

main(int ac, char **av)
        int fd = open(av[1], O_WRONLY);
        if (fd >= 0)
                char buf[12];
                write(fd, buf, 1);
                if (close(fd) < 0)
                        fprintf(stderr, "Problem closing file: %s\n",
        } else {
                fprintf(stderr, "Problem opening \"%s\": %s\n",
                        av[1], strerror(errno));
        return 0;
share|improve this answer
Wouldn't this corrupt the file, since you are writing undefined data to the beginning of it? – Michael Kjörling Sep 28 '12 at 7:29
Yes. But it was the simplest example I could find. – Bruce Ediger Sep 28 '12 at 13:04

The utime/utimes syscall lets you set the access and modification time arbitrarily. So you can stat the file, then use utime to change only one of them. From the man page:


utime, utimes - change file last access and modification times


   #include <sys/types.h>
   #include <utime.h>

   int utime(const char *filename, const struct utimbuf *times);

   #include <sys/time.h>

   int utimes(const char *filename, const struct timeval times[2]);


The utime() system call changes the access and modification times of the inode specified by filename to the actime and modtime fields of times respectively.

If times is NULL, then the access and modification times of the file are set to the current time.

Changing timestamps is permitted when: either the process has appropri‐ ate privileges, or the effective user ID equals the user ID of the file, or times is NULL and the process has write permission for the file.

[ … ]

share|improve this answer

Remount the FS with noatime attribute, change the file, and remount it back.

share|improve this answer

Include the -m argument to touch. By default, the touch command modifies both the access time and the modification time; if you pass either -a or -m then only the specified time is modified.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.