I know how to change the timestamp of a regular file:

touch -t 201301291810 myfile.txt

I was not able to do the same with a symlink. Is it possible?

Distro: RHEL 5.8

  • 2
    What is the problem you are trying to solve?
    – mdpc
    Feb 6, 2013 at 17:45
  • 3
    i need to alter a timestamp so the symlink looks like it was created in the past
    – amphibient
    Feb 6, 2013 at 17:52
  • 10
    that is irrelevant. i am not going into my business logic
    – amphibient
    Feb 6, 2013 at 18:16
  • 5
    This type of information helps us all to get to a solution that would work for you. Its not irreleveant. Sorry you are so sensitive, I'm just trying to help.
    – mdpc
    Feb 6, 2013 at 18:30
  • 6
    dude, it is irrelevant. just go with the need for changing the timestamp as a given constant, invariable. you can question it all you want but it is not changing on my end. which makes the questioning pretty much useless, effectively. good luck
    – amphibient
    Feb 6, 2013 at 18:33

4 Answers 4


add switch -h

touch -h -t 201301291810 myfile.txt

Mandatory arguments to long options are mandatory for short options too.
  -a                     change only the access time
  -c, --no-create        do not create any files
  -d, --date=STRING      parse STRING and use it instead of current time
  -f                     (ignored)
  -h, --no-dereference   affect each symbolic link instead of any referenced
                         file (useful only on systems that can change the
                         timestamps of a symlink)
  -m                     change only the modification time
  -r, --reference=FILE   use this file's times instead of current time
  -t STAMP               use [[CC]YY]MMDDhhmm[.ss] instead of current time
  • > touch -h -t 201301291810 mysymlink -> touch: invalid option -- h Try `touch --help' for more information.
    – amphibient
    Feb 6, 2013 at 15:42
  • 5
    look at the quote "useful only on systems that can change the timestamps of a symlink".
    – mdpc
    Feb 6, 2013 at 17:44
  • 4
    It was also only added recently (it's not in this manpage from 2010). Maybe he needs to just get the latest version of coreutils. Here's the diff of when it was added in 2009
    – Random832
    Feb 6, 2013 at 17:49
  • If this is the correct answer, please mark it as such.
    – qodeninja
    Aug 18, 2019 at 20:58
  • 1
    Note that for touch to support -h the system must also implement the actual C method lutimes(). Not all systems support this. Feb 18, 2021 at 12:09

You may need a more recent version of touch. If this is not an option, and if you know C, you could write a small program to do it yourself using the lutimes function.


A brute force way is as follows:

 0. delete the old symlink you wish to change     
 1. change the system date to whatever date you want the symlink to be
 2. remake the symlink
 3. return the system date to current.
  • made me curious, what system requires this? btw, any file created while you have not yet fixed the sytem date will have that timestamp too Jun 3, 2014 at 21:49
  • Because one is unable to modify the symlink inode once created.
    – mdpc
    Jun 3, 2014 at 22:20
  • @mdpc See lutimes(). Feb 18, 2021 at 12:10

The atime and mtime of a symbolic link can be changed using the lutimes function. The following program works for me on MacOSX and Linux to copy both times from an arbitrary file to a symbolic link:

#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/time.h>

main(int argc, char **argv)
    struct timeval times[2];
    struct stat info;
    int rc;

    if (argc != 3) {
        fprintf(stderr, "usage: %s source target\n", argv[0]);
        return 1;
    rc = lstat(argv[1], &info);
    if (rc != 0) {
        fprintf(stderr, "error: cannot stat %s, %s\n", argv[1],
        return 1;

    times[0].tv_sec = info.st_atime;
    times[0].tv_usec = 0;
    times[1].tv_sec = info.st_mtime;
    times[1].tv_usec = 0;
    rc = lutimes(argv[2], times);
    if (rc != 0) {
        fprintf(stderr, "error: cannot set times on %s, %s\n", argv[2],
        return 1;

    return 0;

If you call the compiled file copytime, then the command copytime file link can be used to make link have the same atime and mtime as file does. It shouldn't be too difficult to modify the program to use times specified on the command line instead of copying the times from another file.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .