GNU bug report logs - #55937
[PATCH] touch: create parent directories if needed

Previous Next

Package: coreutils;

Reported by: Alan Rosenthal <alan.rosenthal <at> gmail.com>

Date: Mon, 13 Jun 2022 04:33:01 UTC

Severity: normal

Tags: patch

Full log


View this message in rfc822 format

From: Alan Rosenthal <alan.rosenthal <at> gmail.com>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 55937 <at> debbugs.gnu.org
Subject: bug#55937: [PATCH] touch: create parent directories if needed
Date: Wed, 15 Jun 2022 16:31:47 -0400
[Message part 1 (text/plain, inline)]
Thanks for taking the time to review my patch.

I agree with you that this change is not strictly required. It's more of a
nice to have / ergonomic improvement to the existing touch interface.

There are several StackOverflow posts that ask for this very feature:
https://unix.stackexchange.com/q/63098 &
https://unix.stackexchange.com/q/305844

Below is the help text for touch:
> Update the access and modification times of each FILE to the current time.
> A FILE argument that does not exist is created empty, unless -c or -h is
supplied.

I was surprised to learn there was no existing flag that would allow
directory creation when a file and its directories do not exist. Currently
if directories do not exist, the command fails. I would go as far to argue
that creating a file also implies creating any required directories, since
directories must exist before we can create said file.

I also agree with David Hilton's recommendation that we should not change
the default behavior of touch, like in my first patch, but rather add an
opt-in flag for this behavior.

Thank you for reading my reply and I look forward to your future feedback.

On Tue, Jun 14, 2022 at 10:37 PM Paul Eggert <eggert <at> cs.ucla.edu> wrote:

> On 6/14/22 19:20, Alan Rosenthal wrote:
> > `touch -p a/b/c/d/e` will now be the same as running:
> > `mkdir -p a/b/c/d && touch a/b/c/d/e`.
>
> I don't see how this useful enough to merit a change, since one can
> achieve the effect of the proposed "touch -p" with the already-existing
> "mkdir -p" followed by plain "touch". mkdir -p already exists and should
> work everywhere that's POSIX-compatible. We don't need -p for other
> commands that create files (e.g., cp, mv, ln); what's special about
> 'touch'?
>
>
[Message part 2 (text/html, inline)]

This bug report was last modified 3 years and 8 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.