bug#79931: possible option additions/changes for GNU "touch"

Paul Eggert <[email protected]> Mon, 1 Dec 2025 09:03:35 -0800
Newsgroups gmane.comp.gnu.core-utils.bugs
Organization UCLA Computer Science Department
Message-ID <[email protected]>
[Opening up a new bug report number for this, in reply to a message 
involving Bug#79907.]

On 2025-12-01 00:25, Stan Marsh wrote:

> I've often wished that "touch" had an option like -c, but the opposite
> - that is, *always* create (and generate an error if the file already
> exists) (*).

What use cases would there be for -c?

NetBSD "touch" has these options:

  -D       Don't change a file's times if they're already OK.
  -R FILE  Like -r FILE, but don't follow symlinks.

I.e., NetBSD -h affects only whether symlinks are followed in the target 
file, not in the reference file. This is incompatible with GNU touch. 
For example, with NetBSD:

    touch -Dhr SYMLINK SYMLINK

updates SYMLINK's timestamp to be that of the file it references; there 
is no easy way to do that with GNU touch. Perhaps we should change GNU 
touch to be compatible with NetBSD in this respect.

FreeBSD "touch" has this option:

   -A [-][[HH]MM]SS]
     Adjust the access and modification times by HH:MM:SS.
     This implies -c.

This is for when you have a bunch of files with wrong timestamps (e.g., 
you imported them from MS-DOS and they had the wrong timezone). This 
might be a useful flag to add to GNU "touch".