From unknown Mon Jun 23 09:39:59 2025 X-Loop: help-debbugs@gnu.org Subject: bug#9742: touch option for existence? Resent-From: Morty Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Thu, 13 Oct 2011 01:52:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 9742 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: 9742@debbugs.gnu.org X-Debbugs-Original-To: bug-coreutils@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.131847072126936 (code B ref -1); Thu, 13 Oct 2011 01:52:01 +0000 Received: (at submit) by debbugs.gnu.org; 13 Oct 2011 01:52:01 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1REASm-00070P-Ch for submit@debbugs.gnu.org; Wed, 12 Oct 2011 21:52:00 -0400 Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1REAN5-0006rZ-BI for submit@debbugs.gnu.org; Wed, 12 Oct 2011 21:46:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1REAMV-0006fP-R5 for submit@debbugs.gnu.org; Wed, 12 Oct 2011 21:45:36 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from lists.gnu.org ([140.186.70.17]:49476) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1REAMV-0006fL-Md for submit@debbugs.gnu.org; Wed, 12 Oct 2011 21:45:31 -0400 Received: from eggs.gnu.org ([140.186.70.92]:45444) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1REAMU-0008AG-Ju for bug-coreutils@gnu.org; Wed, 12 Oct 2011 21:45:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1REAMT-0006ec-DX for bug-coreutils@gnu.org; Wed, 12 Oct 2011 21:45:30 -0400 Received: from qmta10.emeryville.ca.mail.comcast.net ([76.96.30.17]:46476) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1REAMT-0006dh-8m for bug-coreutils@gnu.org; Wed, 12 Oct 2011 21:45:29 -0400 Received: from omta24.emeryville.ca.mail.comcast.net ([76.96.30.92]) by qmta10.emeryville.ca.mail.comcast.net with comcast id k1El1h0031zF43QAA1lLEL; Thu, 13 Oct 2011 01:45:20 +0000 Received: from frakir.org ([76.111.15.187]) by omta24.emeryville.ca.mail.comcast.net with comcast id k1u01h00T429Q8k8k1u1hp; Thu, 13 Oct 2011 01:54:01 +0000 Received: by frakir.org (Postfix, from userid 501) id 64BDE20843B; Wed, 12 Oct 2011 21:45:25 -0400 (EDT) Date: Wed, 12 Oct 2011 21:45:25 -0400 From: Morty Message-ID: <20111013014525.GA6199@red-sonja> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.17 X-Spam-Score: -6.0 (------) X-Mailman-Approved-At: Wed, 12 Oct 2011 21:51:59 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -6.0 (------) [This is more of a feature request than a bug request. But I don't see where I can make feature requests.] It would be nice if touch had an option to only "touch" if the file doesn't already exist. Sort of like -c, but the other way around. This is useful because often, the reason one is using "touch" in a script is because one wants to make sure that a file exists before doing an operation that expects the file to already exist. But if the file already exists, then touch has a side effect of changing the mtime or the atime. [On many systems, one can work on a file without changing the atime thanks to mount options such as noatime or relatime.] It's easy enough to wrap touch in an if: if [ ! -e $file ]; then touch $file; fi But it would be nicer if this common case were built in. I would suggest -e, for exists. Thanks! - Morty From unknown Mon Jun 23 09:39:59 2025 X-Loop: help-debbugs@gnu.org Subject: bug#9742: touch option for existence? Resent-From: =?UTF-8?Q?P=C3=A1draig?= Brady Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Thu, 13 Oct 2011 09:06:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 9742 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: Morty Cc: 9742@debbugs.gnu.org Received: via spool by 9742-submit@debbugs.gnu.org id=B9742.131849674232534 (code B ref 9742); Thu, 13 Oct 2011 09:06:02 +0000 Received: (at 9742) by debbugs.gnu.org; 13 Oct 2011 09:05:42 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1REHET-0008Sg-Gh for submit@debbugs.gnu.org; Thu, 13 Oct 2011 05:05:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1REHER-0008SV-Ct for 9742@debbugs.gnu.org; Thu, 13 Oct 2011 05:05:40 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p9D957O8013745 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 13 Oct 2011 05:05:07 -0400 Received: from [10.3.113.89] (ovpn-113-89.phx2.redhat.com [10.3.113.89]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p9D955UR020230 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 13 Oct 2011 05:05:06 -0400 Message-ID: <4E96A9C1.2020104@draigBrady.com> Date: Thu, 13 Oct 2011 10:05:05 +0100 From: =?UTF-8?Q?P=C3=A1draig?= Brady User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:6.0) Gecko/20110816 Thunderbird/6.0 MIME-Version: 1.0 References: <20111013014525.GA6199@red-sonja> In-Reply-To: <20111013014525.GA6199@red-sonja> X-Enigmail-Version: 1.3.2 Content-Type: text/plain; charset=ISO-8859-1 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id p9D957O8013745 X-Spam-Score: -10.6 (----------) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -10.6 (----------) On 10/13/2011 02:45 AM, Morty wrote: > [This is more of a feature request than a bug request. But I don't > see where I can make feature requests.] >=20 > It would be nice if touch had an option to only "touch" if the file > doesn't already exist. Sort of like -c, but the other way around. > This is useful because often, the reason one is using "touch" in a > script is because one wants to make sure that a file exists before > doing an operation that expects the file to already exist. But if the > file already exists, then touch has a side effect of changing the > mtime or the atime. [On many systems, one can work on a file without > changing the atime thanks to mount options such as noatime or > relatime.] >=20 > It's easy enough to wrap touch in an if: >=20 > if [ ! -e $file ]; then touch $file; fi >=20 > But it would be nicer if this common case were built in. I would > suggest -e, for exists. Thanks! Note the above is easier to express in shell like: [ -e "$file" ] || touch "$file" But that is racy. If you were using touch for locking purposes then adding -e (must create), would allow one to add O_EXCL to the open()= , so you could then do things like: until touch -e "$lock_file"; do sleep .1; done However that functionality is already supported like: until mkdir "$lock_dir"; do sleep .1; done So I'm not sure this is warranted. I'm 60:40 against currently. cheers, P=E1draig. From unknown Mon Jun 23 09:39:59 2025 X-Loop: help-debbugs@gnu.org Subject: bug#9742: touch option for existence? Resent-From: Morty Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Thu, 13 Oct 2011 13:22:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 9742 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: =?UTF-8?Q?P=C3=A1draig?= Brady Cc: 9742@debbugs.gnu.org, Morty Received: via spool by 9742-submit@debbugs.gnu.org id=B9742.131851210125245 (code B ref 9742); Thu, 13 Oct 2011 13:22:01 +0000 Received: (at 9742) by debbugs.gnu.org; 13 Oct 2011 13:21:41 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RELED-0006Z8-Ir for submit@debbugs.gnu.org; Thu, 13 Oct 2011 09:21:41 -0400 Received: from qmta01.westchester.pa.mail.comcast.net ([76.96.62.16]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RELEB-0006Yr-LU for 9742@debbugs.gnu.org; Thu, 13 Oct 2011 09:21:41 -0400 Received: from omta22.westchester.pa.mail.comcast.net ([76.96.62.73]) by qmta01.westchester.pa.mail.comcast.net with comcast id kBzl1h0011ap0As51DM6aU; Thu, 13 Oct 2011 13:21:06 +0000 Received: from frakir.org ([76.111.15.187]) by omta22.westchester.pa.mail.comcast.net with comcast id kDM61h00g429Q8k3iDM60A; Thu, 13 Oct 2011 13:21:06 +0000 Received: by frakir.org (Postfix, from userid 501) id 0D1282081F4; Thu, 13 Oct 2011 09:21:05 -0400 (EDT) Date: Thu, 13 Oct 2011 09:21:05 -0400 From: Morty Message-ID: <20111013132104.GA27645@red-sonja> References: <20111013014525.GA6199@red-sonja> <4E96A9C1.2020104@draigBrady.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <4E96A9C1.2020104@draigBrady.com> User-Agent: Mutt/1.5.20 (2009-06-14) X-Spam-Score: -4.3 (----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -3.7 (---) On Thu, Oct 13, 2011 at 10:05:05AM +0100, Pádraig Brady wrote: > Note the above is easier to express in shell like: > > [ -e "$file" ] || touch "$file" Thanks, I'm familiar with it. :) > But that is racy. If you were using touch for locking purposes I'm using touch to make sure the file exists before an operation that will yield an error if it doesn't exist. For example: resolv=/etc/resolv.conf touch $resolv ci -l -t-$resolv -m"check-in existing" $resolv grep -q domain $resolv || echo domain $domain >> $resolv ci -l -m"add domain $domain" $resolv The intent of code like the above is to make sure a certain file is in revision control and contains a certain setting. If the file already is in revision control and has the setting, the code should do nothing. But touch changes the mtime. The problem could be fixed by slinging around ifs, but that's inelegant. - Morty From debbugs-submit-bounces@debbugs.gnu.org Thu Oct 13 09:38:15 2011 Received: (at control) by debbugs.gnu.org; 13 Oct 2011 13:38:15 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RELUF-0006vr-DF for submit@debbugs.gnu.org; Thu, 13 Oct 2011 09:38:15 -0400 Received: from mx.meyering.net ([88.168.87.75]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RELUC-0006ve-N0; Thu, 13 Oct 2011 09:38:14 -0400 Received: from rho.meyering.net (localhost.localdomain [127.0.0.1]) by rho.meyering.net (Acme Bit-Twister) with ESMTP id 5107C60042; Thu, 13 Oct 2011 15:37:42 +0200 (CEST) From: Jim Meyering To: Morty Subject: Re: bug#9742: touch option for existence? In-Reply-To: <20111013132104.GA27645@red-sonja> (Morty's message of "Thu, 13 Oct 2011 09:21:05 -0400") References: <20111013014525.GA6199@red-sonja> <4E96A9C1.2020104@draigBrady.com> <20111013132104.GA27645@red-sonja> Date: Thu, 13 Oct 2011 15:37:42 +0200 Message-ID: <8739exc8rd.fsf@rho.meyering.net> Lines: 40 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.9 (--) X-Debbugs-Envelope-To: control Cc: =?iso-8859-1?Q?P=E1draig?= Brady , 9742-close@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.9 (--) tags 9742 + notabug thanks Morty wrote: > On Thu, Oct 13, 2011 at 10:05:05AM +0100, P=E1draig Brady wrote: > >> Note the above is easier to express in shell like: >> >> [ -e "$file" ] || touch "$file" > > Thanks, I'm familiar with it. :) > >> But that is racy. If you were using touch for locking purposes > > I'm using touch to make sure the file exists before an operation that > will yield an error if it doesn't exist. For example: Thanks for the suggestion. However, when there's such an easy and portable way to do what you want, touch_if_absent() { test -e "$1" || touch "$1"; } it is counterproductive (and contrary to the "Unix way") to encumber a tool like "touch" with an option to provide that functionality. Besides, then you'd have to wait until a release including your option makes it into whatever distribution you use (or build from source). With the above, you have something that is portable and works now. > resolv=3D/etc/resolv.conf > touch $resolv > ci -l -t-$resolv -m"check-in existing" $resolv > grep -q domain $resolv || echo domain $domain >> $resolv > ci -l -m"add domain $domain" $resolv > > The intent of code like the above is to make sure a certain file is in > revision control and contains a certain setting. If the file already > is in revision control and has the setting, the code should do > nothing. But touch changes the mtime. The problem could be fixed by > slinging around ifs, but that's inelegant. From unknown Mon Jun 23 09:39:59 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.427 (Entity 5.427) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Morty Subject: bug#9742: closed (Re: bug#9742: touch option for existence?) Message-ID: References: <8739exc8rd.fsf@rho.meyering.net> <20111013014525.GA6199@red-sonja> X-Gnu-PR-Message: they-closed 9742 X-Gnu-PR-Package: coreutils X-Gnu-PR-Keywords: notabug Reply-To: 9742@debbugs.gnu.org Date: Thu, 13 Oct 2011 13:39:03 +0000 Content-Type: multipart/mixed; boundary="----------=_1318513143-26726-1" This is a multi-part message in MIME format... ------------=_1318513143-26726-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #9742: touch option for existence? which was filed against the coreutils package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 9742@debbugs.gnu.org. --=20 9742: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D9742 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1318513143-26726-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 9742-close) by debbugs.gnu.org; 13 Oct 2011 13:38:15 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RELUF-0006vp-0e for submit@debbugs.gnu.org; Thu, 13 Oct 2011 09:38:15 -0400 Received: from mx.meyering.net ([88.168.87.75]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RELUC-0006ve-N0; Thu, 13 Oct 2011 09:38:14 -0400 Received: from rho.meyering.net (localhost.localdomain [127.0.0.1]) by rho.meyering.net (Acme Bit-Twister) with ESMTP id 5107C60042; Thu, 13 Oct 2011 15:37:42 +0200 (CEST) From: Jim Meyering To: Morty Subject: Re: bug#9742: touch option for existence? In-Reply-To: <20111013132104.GA27645@red-sonja> (Morty's message of "Thu, 13 Oct 2011 09:21:05 -0400") References: <20111013014525.GA6199@red-sonja> <4E96A9C1.2020104@draigBrady.com> <20111013132104.GA27645@red-sonja> Date: Thu, 13 Oct 2011 15:37:42 +0200 Message-ID: <8739exc8rd.fsf@rho.meyering.net> Lines: 40 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.9 (--) X-Debbugs-Envelope-To: 9742-close Cc: =?iso-8859-1?Q?P=E1draig?= Brady , 9742-close@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.9 (--) tags 9742 + notabug thanks Morty wrote: > On Thu, Oct 13, 2011 at 10:05:05AM +0100, P=E1draig Brady wrote: > >> Note the above is easier to express in shell like: >> >> [ -e "$file" ] || touch "$file" > > Thanks, I'm familiar with it. :) > >> But that is racy. If you were using touch for locking purposes > > I'm using touch to make sure the file exists before an operation that > will yield an error if it doesn't exist. For example: Thanks for the suggestion. However, when there's such an easy and portable way to do what you want, touch_if_absent() { test -e "$1" || touch "$1"; } it is counterproductive (and contrary to the "Unix way") to encumber a tool like "touch" with an option to provide that functionality. Besides, then you'd have to wait until a release including your option makes it into whatever distribution you use (or build from source). With the above, you have something that is portable and works now. > resolv=3D/etc/resolv.conf > touch $resolv > ci -l -t-$resolv -m"check-in existing" $resolv > grep -q domain $resolv || echo domain $domain >> $resolv > ci -l -m"add domain $domain" $resolv > > The intent of code like the above is to make sure a certain file is in > revision control and contains a certain setting. If the file already > is in revision control and has the setting, the code should do > nothing. But touch changes the mtime. The problem could be fixed by > slinging around ifs, but that's inelegant. ------------=_1318513143-26726-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 13 Oct 2011 01:52:01 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1REASm-00070P-Ch for submit@debbugs.gnu.org; Wed, 12 Oct 2011 21:52:00 -0400 Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1REAN5-0006rZ-BI for submit@debbugs.gnu.org; Wed, 12 Oct 2011 21:46:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1REAMV-0006fP-R5 for submit@debbugs.gnu.org; Wed, 12 Oct 2011 21:45:36 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from lists.gnu.org ([140.186.70.17]:49476) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1REAMV-0006fL-Md for submit@debbugs.gnu.org; Wed, 12 Oct 2011 21:45:31 -0400 Received: from eggs.gnu.org ([140.186.70.92]:45444) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1REAMU-0008AG-Ju for bug-coreutils@gnu.org; Wed, 12 Oct 2011 21:45:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1REAMT-0006ec-DX for bug-coreutils@gnu.org; Wed, 12 Oct 2011 21:45:30 -0400 Received: from qmta10.emeryville.ca.mail.comcast.net ([76.96.30.17]:46476) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1REAMT-0006dh-8m for bug-coreutils@gnu.org; Wed, 12 Oct 2011 21:45:29 -0400 Received: from omta24.emeryville.ca.mail.comcast.net ([76.96.30.92]) by qmta10.emeryville.ca.mail.comcast.net with comcast id k1El1h0031zF43QAA1lLEL; Thu, 13 Oct 2011 01:45:20 +0000 Received: from frakir.org ([76.111.15.187]) by omta24.emeryville.ca.mail.comcast.net with comcast id k1u01h00T429Q8k8k1u1hp; Thu, 13 Oct 2011 01:54:01 +0000 Received: by frakir.org (Postfix, from userid 501) id 64BDE20843B; Wed, 12 Oct 2011 21:45:25 -0400 (EDT) Date: Wed, 12 Oct 2011 21:45:25 -0400 From: Morty To: bug-coreutils@gnu.org Subject: touch option for existence? Message-ID: <20111013014525.GA6199@red-sonja> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.17 X-Spam-Score: -6.0 (------) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Wed, 12 Oct 2011 21:51:59 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -6.0 (------) [This is more of a feature request than a bug request. But I don't see where I can make feature requests.] It would be nice if touch had an option to only "touch" if the file doesn't already exist. Sort of like -c, but the other way around. This is useful because often, the reason one is using "touch" in a script is because one wants to make sure that a file exists before doing an operation that expects the file to already exist. But if the file already exists, then touch has a side effect of changing the mtime or the atime. [On many systems, one can work on a file without changing the atime thanks to mount options such as noatime or relatime.] It's easy enough to wrap touch in an if: if [ ! -e $file ]; then touch $file; fi But it would be nicer if this common case were built in. I would suggest -e, for exists. Thanks! - Morty ------------=_1318513143-26726-1-- From unknown Mon Jun 23 09:39:59 2025 X-Loop: help-debbugs@gnu.org Subject: bug#9742: touch option for existence? Resent-From: Eric Blake Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Thu, 13 Oct 2011 14:10:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 9742 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: notabug To: =?UTF-8?Q?P=C3=A1draig?= Brady Cc: 9742@debbugs.gnu.org, Morty Received: via spool by 9742-submit@debbugs.gnu.org id=B9742.131851498732650 (code B ref 9742); Thu, 13 Oct 2011 14:10:01 +0000 Received: (at 9742) by debbugs.gnu.org; 13 Oct 2011 14:09:47 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RELyk-0008UZ-Mq for submit@debbugs.gnu.org; Thu, 13 Oct 2011 10:09:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RELyh-0008UR-GM for 9742@debbugs.gnu.org; Thu, 13 Oct 2011 10:09:45 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p9DE9ENO030801 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 13 Oct 2011 10:09:14 -0400 Received: from [10.3.113.147] (ovpn-113-147.phx2.redhat.com [10.3.113.147]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p9DE9DqO021035; Thu, 13 Oct 2011 10:09:13 -0400 Message-ID: <4E96F109.6000202@redhat.com> Date: Thu, 13 Oct 2011 08:09:13 -0600 From: Eric Blake Organization: Red Hat User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110928 Fedora/3.1.15-1.fc14 Lightning/1.0b3pre Mnenhy/0.8.4 Thunderbird/3.1.15 MIME-Version: 1.0 References: <20111013014525.GA6199@red-sonja> <4E96A9C1.2020104@draigBrady.com> In-Reply-To: <4E96A9C1.2020104@draigBrady.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id p9DE9ENO030801 X-Spam-Score: -10.3 (----------) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -10.3 (----------) On 10/13/2011 03:05 AM, P=E1draig Brady wrote: > Note the above is easier to express in shell like: > > [ -e "$file" ] || touch "$file" > > But that is racy. If you were using touch for locking purposes > then adding -e (must create), would allow one to add O_EXCL to the open= (), You can avoid that race, while still accomplishing your goal of creating=20 the file if it does not exist, all without corrupting timestamps if it=20 does exist, by using straight shell: (set -C; : > "$file") 2>/dev/null || : --=20 Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org From unknown Mon Jun 23 09:39:59 2025 X-Loop: help-debbugs@gnu.org Subject: bug#9742: touch option for existence? Resent-From: Paul Eggert Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Thu, 13 Oct 2011 15:13:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 9742 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: notabug To: 9742@debbugs.gnu.org, jim@meyering.net Received: via spool by 9742-submit@debbugs.gnu.org id=B9742.13185187535605 (code B ref 9742); Thu, 13 Oct 2011 15:13:02 +0000 Received: (at 9742) by debbugs.gnu.org; 13 Oct 2011 15:12:33 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1REMxV-0001SM-60 for submit@debbugs.gnu.org; Thu, 13 Oct 2011 11:12:33 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1REMxR-0001S6-BG for 9742@debbugs.gnu.org; Thu, 13 Oct 2011 11:12:31 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 5196339E800A; Thu, 13 Oct 2011 08:11:54 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6WJ5h+Nh2QUj; Thu, 13 Oct 2011 08:11:54 -0700 (PDT) Received: from [131.179.64.200] (Penguin.CS.UCLA.EDU [131.179.64.200]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id F38ED39E8008; Thu, 13 Oct 2011 08:11:53 -0700 (PDT) Message-ID: <4E96FFB9.20901@cs.ucla.edu> Date: Thu, 13 Oct 2011 08:11:53 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110928 Fedora/3.1.15-1.fc14 Thunderbird/3.1.15 MIME-Version: 1.0 References: <20111013014525.GA6199@red-sonja> <4E96A9C1.2020104@draigBrady.com> <20111013132104.GA27645@red-sonja> <8739exc8rd.fsf@rho.meyering.net> In-Reply-To: <8739exc8rd.fsf@rho.meyering.net> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam-Score: -3.1 (---) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -3.1 (---) Classic "touch" has always bothered me: touch -a FOO updates FOO's last-access time. touch -m FOO updates FOO's last-modification time. touch -a -m FOO updates both times. Logically, then, "touch FOO", with neither -a nor -m, should update neither time. But it doesn't. It updates both times. I know why this is so -- among other things, it's historical practice and we can't change the above behavior. Still, there ought to be a way for "touch" to update neither time, via a GNU extension. This would make the behavior of GNU touch more orthogonal. This is why I have long been thinking of adding a new option that would mean "neither -a nor -m". Admittedly it's low priority.