How do i change the timestamp of a file in linux only if it already exists?

  • Man page for touch.

           -c, --no-create
                  do not create any files

    If a file already exists for example.

    $ ls -l afile
    -rw-r--r-- 1 training training 0 Jun  3 06:13 afile

    Then running the touch command with the -c option will update the timestamp.

    $ touch -c afile
    $ ls -l 
    -rw-r--r-- 1 training training 0 Jun  7 10:20 afile

© Lightnetics 2022