Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

You don't have to know how the computer works, just how to work the computer.


devel / comp.unix.shell / Removing empty directories

SubjectAuthor
* Removing empty directoriesJanis Papanagnou
+- Re: Removing empty directoriesmarrgol
+- Re: Removing empty directoriesBen Collver
+- Re: Removing empty directoriesKenny McCormack
+* Re: Removing empty directoriesKaz Kylheku
|+* Re: Removing empty directoriesChristian Weisgerber
||`* Re: Removing empty directoriesKaz Kylheku
|| `- Re: Removing empty directoriesChristian Weisgerber
|`- Re: Removing empty directoriesHelmut Waitzmann
+* Re: Removing empty directoriesBen Bacarisse
|+* Re: Removing empty directoriesJanis Papanagnou
||+* Re: Removing empty directoriesAragorn
|||`* Re: Removing empty directoriesJanis Papanagnou
||| `* Long options, like it or not, are the future (Was: Removing empty directories)Kenny McCormack
|||  +* Re: Long options, like it or not, are the future (Was: Removing emptyChris Elvidge
|||  |`- Re: Long options, like it or not, are the futureHelmut Waitzmann
|||  +* Re: Long options, like it or not, are the future (Was: RemovingKaz Kylheku
|||  |`* Re: Long options, like it or not, are the futureDan Espen
|||  | `* Re: Long options, like it or not, are the futureKaz Kylheku
|||  |  `* Re: Long options, like it or not, are the futureDan Espen
|||  |   `- Re: Long options, like it or not, are the futureKaz Kylheku
|||  `- Re: Long options, like it or not, are the future (Was: Removing emptyJanis Papanagnou
||`- Re: Removing empty directoriesBen Bacarisse
|`- Re: Removing empty directoriesKaz Kylheku
+* Re: Removing empty directoriesHelmut Waitzmann
|`* Re: Removing empty directoriesKaz Kylheku
| `* Re: Removing empty directoriesHelmut Waitzmann
|  `- Re: Removing empty directoriesKaz Kylheku
+* Re: Removing empty directoriesLew Pitcher
|`- Re: Removing empty directoriesKaz Kylheku
`* Re: Removing empty directoriesBrian Patrie
 `* Re: Removing empty directoriesJanis Papanagnou
  `* Re: Removing empty directoriesJanis Papanagnou
   `* Re: Removing empty directoriesEric Pozharski
    `* Re: Removing empty directoriesBrian Patrie
     +* Re: Removing empty directoriesKaz Kylheku
     |+- Re: Removing empty directoriesKaz Kylheku
     |`- Re: Removing empty directoriesJanis Papanagnou
     `* Re: Removing empty directoriesJanis Papanagnou
      +* Re: Removing empty directoriesEric Pozharski
      |`* Going down the zsh rabbit-hole... (Was: Removing empty directories)Kenny McCormack
      | +- Re: Going down the zsh rabbit-hole... (Was: Removing emptyEric Pozharski
      | `* Re: Going down the zsh rabbit-hole... (Was: Removing emptyJanis Papanagnou
      |  `* Re: Going down the zsh rabbit-hole... (Was: Removing emptyEric Pozharski
      |   `* Re: Going down the zsh rabbit-hole... (Was: Removing emptyJanis Papanagnou
      |    `* Re: Going down the zsh rabbit-hole... (Was: Removing emptyJanis Papanagnou
      |     `* Re: Going down the zsh rabbit-hole... (Was: Removing emptyEric Pozharski
      |      `* Re: Going down the zsh rabbit-hole... (Was: Removing emptyJanis Papanagnou
      |       `* Re: Going down the zsh rabbit-hole... (Was: Removing emptyEric Pozharski
      |        `- Re: Going down the zsh rabbit-hole... (Was: Removing emptyJanis Papanagnou
      `* Re: Removing empty directoriesBrian Patrie
       `- Re: Removing empty directoriesKaz Kylheku

Pages:123
Removing empty directories

<t870s4$118f$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5352&group=comp.unix.shell#5352

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!T3K46XQNoj8Ozlxp+kkIuw.user.46.165.242.75.POSTED!not-for-mail
From: janis_papanagnou@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Removing empty directories
Date: Mon, 13 Jun 2022 11:43:31 +0200
Organization: Aioe.org NNTP Server
Message-ID: <t870s4$118f$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="34063"; posting-host="T3K46XQNoj8Ozlxp+kkIuw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Janis Papanagnou - Mon, 13 Jun 2022 09:43 UTC

Is there some elegant way to test/remove an empty directory?

Currently I am unconditionally doing rmdir "$dir" 2>/dev/null
where an empty directory will be removed, and the error message
in case of non-empty directories suppressed. It works, but that
way I suppress all error information which might have undesired
or undetected bad effects. So I was looking for some test based
approach like [[...]] && rmdir "$dir" but couldn't find simple
tests for that (e.g. -d and link count comparison isn't really
elegant either, the same with something like ls .* * 2>/dev/null
and string comparisons, or similar).

The rmdir(1) command is delegated to the rmdir(2) system call.
What would rmdir(2) do to determine the emptiness? Would we
have to do something similar/complex or am I missing something
obvious?

Janis

Re: Removing empty directories

<62a728cf$0$555$65785112@news.neostrada.pl>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5353&group=comp.unix.shell#5353

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!newsfeed.neostrada.pl!unt-exc-02.news.neostrada.pl!unt-spo-a-02.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mail
Subject: Re: Removing empty directories
Newsgroups: comp.unix.shell
References: <t870s4$118f$1@gioia.aioe.org>
From: marrgol@address.invalid (marrgol)
Date: Mon, 13 Jun 2022 14:08:47 +0200
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
MIME-Version: 1.0
In-Reply-To: <t870s4$118f$1@gioia.aioe.org>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
Lines: 14
Message-ID: <62a728cf$0$555$65785112@news.neostrada.pl>
Organization: Telekomunikacja Polska
NNTP-Posting-Host: 176.111.237.144
X-Trace: 1655122127 unt-rea-b-01.news.neostrada.pl 555 176.111.237.144:58972
X-Complaints-To: abuse@news.neostrada.pl
X-Received-Bytes: 1324
 by: marrgol - Mon, 13 Jun 2022 12:08 UTC

On 13/06/2022 at 11.43, Janis Papanagnou wrote:
> Is there some elegant way to test/remove an empty directory?

I use 'find' for this. E.g. assuming $dir is just a name, not a path,
and it is in current directory:

$ find . -maxdepth 1 -type d -name "$dir" -empty -delete

I usually skip '-maxdepth 1' to also delete all empty sub-directories
of $dir.

--
mrg

Re: Removing empty directories

<slrntaebn7.g9f.bencollver@svadhyaya.localdomain>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5354&group=comp.unix.shell#5354

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bencollver@tilde.pink (Ben Collver)
Newsgroups: comp.unix.shell
Subject: Re: Removing empty directories
Date: Mon, 13 Jun 2022 12:35:44 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <slrntaebn7.g9f.bencollver@svadhyaya.localdomain>
References: <t870s4$118f$1@gioia.aioe.org>
Injection-Date: Mon, 13 Jun 2022 12:35:44 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="260933b9a09297be9fe143a0c6e2d503";
logging-data="18197"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/KmS3v9XOTyCHB0PGJFEJmbvgyf093IGs="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:n5CCyCp0PEUPZ8acr5D8jVbMhKA=
 by: Ben Collver - Mon, 13 Jun 2022 12:35 UTC

On 2022-06-13, Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
> Is there some elegant way to test/remove an empty directory?
>
> Currently I am unconditionally doing rmdir "$dir" 2>/dev/null
> where an empty directory will be removed, and the error message
> in case of non-empty directories suppressed. It works, but that
> way I suppress all error information which might have undesired
> or undetected bad effects. So I was looking for some test based
> approach like [[...]] && rmdir "$dir" but couldn't find simple
> tests for that (e.g. -d and link count comparison isn't really
> elegant either, the same with something like ls .* * 2>/dev/null
> and string comparisons, or similar).
>
> The rmdir(1) command is delegated to the rmdir(2) system call.
> What would rmdir(2) do to determine the emptiness? Would we
> have to do something similar/complex or am I missing something
> obvious?
>
> Janis

Here's an idea for bash:

(shopt -s dotglob; cd dir; if [ -z "$(ls)" ]; then \
echo empty; else echo full; fi)

Re: Removing empty directories

<t87bfq$1gmq9$1@news.xmission.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5355&group=comp.unix.shell#5355

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!1.us.feeder.erje.net!feeder.erje.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Re: Removing empty directories
Date: Mon, 13 Jun 2022 12:44:42 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <t87bfq$1gmq9$1@news.xmission.com>
References: <t870s4$118f$1@gioia.aioe.org>
Injection-Date: Mon, 13 Jun 2022 12:44:42 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="1596233"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Mon, 13 Jun 2022 12:44 UTC

In article <t870s4$118f$1@gioia.aioe.org>,
Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
>Is there some elegant way to test/remove an empty directory?

I assume that the basic answer to your question is going to be: NO.

I.e., I assume you are familiar with and, more importantly, entirely
capable of working out on your own any/all of the available kludgey
workarounds. Another user has given a kludgey workaround using "find".

Keep in mind that any version of the form "test/find an empty directory,
then remove it" could fail due to the "race condition" - i.e., whatever
that fancy acronym is for "time of test/time of use".

FWIW, here is an idea that I have used in some of my scripts, where there
is one error message that you anticipate (and which, therefore, is not
really an error), but you still want to capture any other (unexpected)
error messages:

someCommand 2>&1 | grep -v "Expected Error Message"

Nitpickers note: Note that this ignores "errorlevel"; some polish may be
needed to get the errorlevel to come out right. The bash option "pipefail"
may be useful here...

--
You are again heaping damnation upon your own head by your statements.

- Rick C Hodgin -

Re: Removing empty directories

<20220613052944.117@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5356&group=comp.unix.shell#5356

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 480-992-1380@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: Removing empty directories
Date: Mon, 13 Jun 2022 12:50:00 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <20220613052944.117@kylheku.com>
References: <t870s4$118f$1@gioia.aioe.org>
Injection-Date: Mon, 13 Jun 2022 12:50:00 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="c98c5321993b49bebb0d956500614af3";
logging-data="9515"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19B+kZ5kUiRdATR8SIFFrXcFkQuD1IivFU="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:x2MuBK/k+4LRdZ2VjJlSKc3P8XU=
 by: Kaz Kylheku - Mon, 13 Jun 2022 12:50 UTC

On 2022-06-13, Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
> The rmdir(1) command is delegated to the rmdir(2) system call.
> What would rmdir(2) do to determine the emptiness?

I believe rmdir must be a dedicated primitive in each filesystem
implementation, including checking the necessary criteria.

The rmdir implementation in a sufficiently Unix-like filesystem can just
look at the link count: an empty (non-root) directory has a link count
of exactly two: one is the "." self link, and the other is its name in
the parent (the thing being deleted).

> Would we
> have to do something similar/complex or am I missing something
> obvious?

GNU find has an -empty directive. This actually opens the directory,
and reads it until it finds an entry which is neither "." nor "..".
I suspect that is the only way which approaches 100% portability across
filesystems.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Re: Removing empty directories

<875yl4n2ik.fsf@bsb.me.uk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5357&group=comp.unix.shell#5357

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.unix.shell
Subject: Re: Removing empty directories
Date: Mon, 13 Jun 2022 13:58:43 +0100
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <875yl4n2ik.fsf@bsb.me.uk>
References: <t870s4$118f$1@gioia.aioe.org>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="c3c5c298cdcf9fdf73e9611245da8f77";
logging-data="13187"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ookfOyQxZYj7jxBhXuqirzC1nxGuin94="
Cancel-Lock: sha1:L9MiSLHj31vvkgjnz2eARfnhB+Y=
sha1:7nSgNE1nHnMkQuKUFsIUGoqvjRE=
X-BSB-Auth: 1.089dd3f061a281a03911.20220613135843BST.875yl4n2ik.fsf@bsb.me.uk
 by: Ben Bacarisse - Mon, 13 Jun 2022 12:58 UTC

Janis Papanagnou <janis_papanagnou@hotmail.com> writes:

> Is there some elegant way to test/remove an empty directory?
>
> Currently I am unconditionally doing rmdir "$dir" 2>/dev/null
> where an empty directory will be removed, and the error message
> in case of non-empty directories suppressed. It works, but that
> way I suppress all error information which might have undesired
> or undetected bad effects.

Depending on what rmdir you have, and what your portability requirements
are, you might find that

rmdir --ignore-fail-on-non-empty "$dir"

does what you want.

--
Ben.

Re: Removing empty directories

<slrntaefli.1i2p.naddy@lorvorc.mips.inka.de>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5358&group=comp.unix.shell#5358

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news.szaf.org!inka.de!mips.inka.de!.POSTED.localhost!not-for-mail
From: naddy@mips.inka.de (Christian Weisgerber)
Newsgroups: comp.unix.shell
Subject: Re: Removing empty directories
Date: Mon, 13 Jun 2022 13:42:10 -0000 (UTC)
Message-ID: <slrntaefli.1i2p.naddy@lorvorc.mips.inka.de>
References: <t870s4$118f$1@gioia.aioe.org> <20220613052944.117@kylheku.com>
Injection-Date: Mon, 13 Jun 2022 13:42:10 -0000 (UTC)
Injection-Info: lorvorc.mips.inka.de; posting-host="localhost:::1";
logging-data="51290"; mail-complaints-to="usenet@mips.inka.de"
User-Agent: slrn/1.0.3 (FreeBSD)
 by: Christian Weisgerber - Mon, 13 Jun 2022 13:42 UTC

On 2022-06-13, Kaz Kylheku <480-992-1380@kylheku.com> wrote:

> The rmdir implementation in a sufficiently Unix-like filesystem can just
> look at the link count: an empty (non-root) directory has a link count
> of exactly two: one is the "." self link, and the other is its name in
> the parent (the thing being deleted).

I seemed to remember something like that, but a quick check shows
that a directory's link count is two plus the number of direct
subdirectories. Other contents, such as files, fifos or symlinks,
are not reflected in the link count.

--
Christian "naddy" Weisgerber naddy@mips.inka.de

Re: Removing empty directories

<20220613075721.407@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5359&group=comp.unix.shell#5359

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 480-992-1380@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: Removing empty directories
Date: Mon, 13 Jun 2022 15:05:37 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <20220613075721.407@kylheku.com>
References: <t870s4$118f$1@gioia.aioe.org> <20220613052944.117@kylheku.com>
<slrntaefli.1i2p.naddy@lorvorc.mips.inka.de>
Injection-Date: Mon, 13 Jun 2022 15:05:37 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="c98c5321993b49bebb0d956500614af3";
logging-data="2741"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18qaaf4dZRAyJQ6FfAXhjtTQmGDI2EkqXU="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:w25g7Kb+kmLHb38Ch7gmHGHmOdg=
 by: Kaz Kylheku - Mon, 13 Jun 2022 15:05 UTC

On 2022-06-13, Christian Weisgerber <naddy@mips.inka.de> wrote:
> On 2022-06-13, Kaz Kylheku <480-992-1380@kylheku.com> wrote:
>
>> The rmdir implementation in a sufficiently Unix-like filesystem can just
>> look at the link count: an empty (non-root) directory has a link count
>> of exactly two: one is the "." self link, and the other is its name in
>> the parent (the thing being deleted).
>
> I seemed to remember something like that, but a quick check shows
> that a directory's link count is two plus the number of direct
> subdirectories.

> Other contents, such as files, fifos or symlinks,
> are not reflected in the link count.

You're right; what was I thinking?

Of something else: namely that the directory link count is only
useful for knowing whether there are subdirectories, which is useful
for optimizing a recursive descent, in the case when you're only
looking for subdirectories.

Interestingly, GNU find doesn't take advantage of this; it is still
reading directory entries of "dir" when invoked as "find . -type d dir",
where dir has no children, even though it has done the stat call on it
informing it of the link count of 2.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Re: Removing empty directories

<slrntafe93.1thq.naddy@lorvorc.mips.inka.de>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5360&group=comp.unix.shell#5360

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!inka.de!mips.inka.de!.POSTED.localhost!not-for-mail
From: naddy@mips.inka.de (Christian Weisgerber)
Newsgroups: comp.unix.shell
Subject: Re: Removing empty directories
Date: Mon, 13 Jun 2022 22:24:35 -0000 (UTC)
Message-ID: <slrntafe93.1thq.naddy@lorvorc.mips.inka.de>
References: <t870s4$118f$1@gioia.aioe.org> <20220613052944.117@kylheku.com>
<slrntaefli.1i2p.naddy@lorvorc.mips.inka.de>
<20220613075721.407@kylheku.com>
Injection-Date: Mon, 13 Jun 2022 22:24:35 -0000 (UTC)
Injection-Info: lorvorc.mips.inka.de; posting-host="localhost:::1";
logging-data="63035"; mail-complaints-to="usenet@mips.inka.de"
User-Agent: slrn/1.0.3 (FreeBSD)
 by: Christian Weisgerber - Mon, 13 Jun 2022 22:24 UTC

On 2022-06-13, Kaz Kylheku <480-992-1380@kylheku.com> wrote:

> Of something else: namely that the directory link count is only
> useful for knowing whether there are subdirectories, which is useful
> for optimizing a recursive descent, in the case when you're only
> looking for subdirectories.

This also reminds me of something... ah, this caveat in GNU find's
man page:

-noleaf
Do not optimize by assuming that directories contain 2 fewer
subdirectories than their hard link count. This option is
needed when searching filesystems that do not follow the Unix
directory-link convention, such as CD-ROM or MS-DOS filesystems
or AFS volume mount points. [...]

--
Christian "naddy" Weisgerber naddy@mips.inka.de

Re: Removing empty directories

<83y1y09lbl.fsf@helmutwaitzmann.news.arcor.de>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5361&group=comp.unix.shell#5361

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!5zbID3I7J9d2hObGz2DhcQ.user.46.165.242.75.POSTED!not-for-mail
From: nn.throttle@xoxy.net (Helmut Waitzmann)
Newsgroups: comp.unix.shell
Subject: Re: Removing empty directories
Date: Tue, 14 Jun 2022 01:48:30 +0200
Organization: Aioe.org NNTP Server
Message-ID: <83y1y09lbl.fsf@helmutwaitzmann.news.arcor.de>
References: <t870s4$118f$1@gioia.aioe.org>
Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: quoted-printable
Injection-Info: gioia.aioe.org; logging-data="58162"; posting-host="5zbID3I7J9d2hObGz2DhcQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)
X-Notice: Filtered by postfilter v. 0.9.2
Mail-Copies-To: nobody
Cancel-Lock: sha1:KzBvYTev0ojyq8Q2nD4jY3t69uM=
Mail-Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
 by: Helmut Waitzmann - Mon, 13 Jun 2022 23:48 UTC

Janis Papanagnou <janis_papanagnou@hotmail.com>:
>Is there some elegant way to test/remove an empty directory?
>

I'm not sure:  Does

{ test -d "$dir" && test -s "$dir" ; }

test for an empty directory?  Then

{ test -d "$dir" && test -s "$dir" ; } ||
rmdir -- "$dir"

should do the job.  (Of course it won't solve the race condition
problem.)

Re: Removing empty directories

<20220613173546.937@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5362&group=comp.unix.shell#5362

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 480-992-1380@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: Removing empty directories
Date: Tue, 14 Jun 2022 00:40:31 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <20220613173546.937@kylheku.com>
References: <t870s4$118f$1@gioia.aioe.org>
<83y1y09lbl.fsf@helmutwaitzmann.news.arcor.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 14 Jun 2022 00:40:31 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="157b33bf86b6f7bf76630a4ae28cffd9";
logging-data="31904"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+D/OKwXZokE7AntMuKd0YJOmXcLJ8+J5s="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:FrZ2yxvYSY84QaYl2o2iVfqo71A=
 by: Kaz Kylheku - Tue, 14 Jun 2022 00:40 UTC

On 2022-06-13, Helmut Waitzmann <nn.throttle@xoxy.net> wrote:
> Janis Papanagnou <janis_papanagnou@hotmail.com>:
>>Is there some elegant way to test/remove an empty directory?
>>
>
> I'm not sure:  Does
>
>
> { test -d "$dir" && test -s "$dir" ; }
>
> test for an empty directory?  Then

The -s test is documented for files. It probably checks the inode
st_size for zero. If it happens to work for a directory also, by doing
the same test, then that won't work because a directory is never
literally empty.do that for directories also, it won't work because a
directory is never literally empty.

By the way, it's inverted: a "test -s f" success means
that f is *not* empty.

I tried it on some emtpy and nonempty directories; it's always
succeeding (indicating non-empty).

Re: Removing empty directories

<t89bfs$pa5$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5363&group=comp.unix.shell#5363

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!7PWwXgqO56VVDeCHePP7RQ.user.46.165.242.75.POSTED!not-for-mail
From: janis_papanagnou@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Removing empty directories
Date: Tue, 14 Jun 2022 08:57:00 +0200
Organization: Aioe.org NNTP Server
Message-ID: <t89bfs$pa5$1@gioia.aioe.org>
References: <t870s4$118f$1@gioia.aioe.org> <875yl4n2ik.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="25925"; posting-host="7PWwXgqO56VVDeCHePP7RQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Janis Papanagnou - Tue, 14 Jun 2022 06:57 UTC

On 13.06.22 14:58, Ben Bacarisse wrote:
> Janis Papanagnou <janis_papanagnou@hotmail.com> writes:
>
>> Is there some elegant way to test/remove an empty directory?

First, thanks to all for the suggestions and thoughts posted!

>>
>> Currently I am unconditionally doing rmdir "$dir" 2>/dev/null
>> where an empty directory will be removed, and the error message
>> in case of non-empty directories suppressed. It works, but that
>> way I suppress all error information which might have undesired
>> or undetected bad effects.
>
> Depending on what rmdir you have, and what your portability requirements
> are, you might find that
>
> rmdir --ignore-fail-on-non-empty "$dir"
>
> does what you want.

This is indeed where I'd consider it best placed, as part of the
rmdir command - similar to the mkdir command with mkdir -p option.
(Would be nice if such an option gets standardized.) - Rethinking
about a separate test; this is probably not that good an idea for
my case, since I want to remove multiple directories and would want
to use shell patterns for that, like rmdir -option <date_pattern>
and individual tests would make a loop over the directory-list
necessary (which is also not an issue with a 'find'-based approach).
Currently I am using that code in a GNU context only, so I can use
the suggested rmdir option.

One thing I am wondering, though, is; why isn't there a short form
of that option available? (There's plenty of free letters available
with the rmdir command.) The thought to mistype the long option, or
the necessity to call the man page and use the mouse to copy/paste
the exact text is not appealing for a shell programmer (concerning
usability).

Janis

Re: Removing empty directories

<20220614110357.4f475343@nx-74205>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5364&group=comp.unix.shell#5364

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: thorongil@telenet.be (Aragorn)
Newsgroups: comp.unix.shell
Subject: Re: Removing empty directories
Date: Tue, 14 Jun 2022 11:03:57 +0200
Organization: A noiseless patient Strider
Lines: 15
Message-ID: <20220614110357.4f475343@nx-74205>
References: <t870s4$118f$1@gioia.aioe.org>
<875yl4n2ik.fsf@bsb.me.uk>
<t89bfs$pa5$1@gioia.aioe.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: reader02.eternal-september.org; posting-host="943b32ccc159ca6dcef3980e47096840";
logging-data="1213"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+NZ7dyEeqwsi6DK44C41+R"
Cancel-Lock: sha1:hh+7mxr1DhhSS9RHZppee3Yr1T4=
X-Newsreader: Claws Mail 4.1.0 (GTK 3.24.34; x86_64-pc-linux-gnu)
 by: Aragorn - Tue, 14 Jun 2022 09:03 UTC

On 14.06.2022 at 08:57, Janis Papanagnou scribbled:

> One thing I am wondering, though, is; why isn't there a short form
> of that option available? (There's plenty of free letters available
> with the rmdir command.) The thought to mistype the long option, or
> the necessity to call the man page and use the mouse to copy/paste
> the exact text is not appealing for a shell programmer (concerning
> usability).

Why not create an alias or a shell function for it?

--
With respect,
= Aragorn =

Re: Removing empty directories

<t89nhn$1qva$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5365&group=comp.unix.shell#5365

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!tg95bLwDfWQ+I1oAs1xdEw.user.46.165.242.75.POSTED!not-for-mail
From: janis_papanagnou@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Removing empty directories
Date: Tue, 14 Jun 2022 12:22:46 +0200
Organization: Aioe.org NNTP Server
Message-ID: <t89nhn$1qva$1@gioia.aioe.org>
References: <t870s4$118f$1@gioia.aioe.org> <875yl4n2ik.fsf@bsb.me.uk>
<t89bfs$pa5$1@gioia.aioe.org> <20220614110357.4f475343@nx-74205>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="60394"; posting-host="tg95bLwDfWQ+I1oAs1xdEw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Janis Papanagnou - Tue, 14 Jun 2022 10:22 UTC

On 14.06.22 11:03, Aragorn wrote:
> On 14.06.2022 at 08:57, Janis Papanagnou scribbled:
>
>> One thing I am wondering, though, is; why isn't there a short form
>> of that option available? (There's plenty of free letters available
>> with the rmdir command.) The thought to mistype the long option, or
>> the necessity to call the man page and use the mouse to copy/paste
>> the exact text is not appealing for a shell programmer (concerning
>> usability).
>
> Why not create an alias or a shell function for it?

Because it's unnecessary overhead and unnecessary complexity. And
aliases are, conceptually, an interactive feature. It's the wrong
approach to put the burden for providing simply usable interfaces
on the users' side - each user with her own workaround/wrapper! -
instead of supporting a user-friendly design in the first place.
YMMV.

The schizophrenic thing in this case is that rmdir's other options
-v (--verbose), -p (--parents) have short and long form definitions
even though the long forms are rather short and easily memorizable
but the one with a pathological length (--ignore-fail-on-non-empty,
that's five word components!) has no short form. And I still wonder
why, what the designers think when doing that. If I'd want users to
*not* use a feature or option I'd certainly choose a name like that.

Janis

Long options, like it or not, are the future (Was: Removing empty directories)

<t89o6a$1hvrj$1@news.xmission.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5366&group=comp.unix.shell#5366

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Long options, like it or not, are the future (Was: Removing empty directories)
Date: Tue, 14 Jun 2022 10:33:46 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <t89o6a$1hvrj$1@news.xmission.com>
References: <t870s4$118f$1@gioia.aioe.org> <t89bfs$pa5$1@gioia.aioe.org> <20220614110357.4f475343@nx-74205> <t89nhn$1qva$1@gioia.aioe.org>
Injection-Date: Tue, 14 Jun 2022 10:33:46 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="1638259"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Tue, 14 Jun 2022 10:33 UTC

In article <t89nhn$1qva$1@gioia.aioe.org>,
Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
....
>The schizophrenic thing in this case is that rmdir's other options
>-v (--verbose), -p (--parents) have short and long form definitions
>even though the long forms are rather short and easily memorizable
>but the one with a pathological length (--ignore-fail-on-non-empty,
>that's five word components!) has no short form. And I still wonder
>why, what the designers think when doing that. If I'd want users to
>*not* use a feature or option I'd certainly choose a name like that.

The future trend, like it or not, is towards more and more longer options,
some, as here, w/o short-form equivalents. I think the general feeling
among the developer community is that short (one letter) options are
ambiguous and generally be avoided. They are retained mostly for
historical compatibility.

A good example of what can go wrong is this: For most programs, most of
the time, "-v" means "be verbose", which means it is A) generally a good
idea to include it, and b) safe to do so. But, in the "pkill" command,
"-v" means (basically) kill everything. Everybody gets bit by this at some
point in their careers; this is why I think pgrep/pkill should be avoided.

It would be good to have a global, system-wide convention that "-v"
*always* means "be verbose" - always - and that it is always safe to
include it on the command line.

Finally, I don't understand your reluctance to use this long option (the 5
word one), since: A) It does exactly what you want (I was wrong to say
there was no non-kludgey answer to your question) and B) You are writing a
script, right?, it is not like you have to type that out interactively.
Just put it in your script and be done with it.

--
Mike Huckabee has yet to consciously uncouple from Josh Duggar.

Re: Long options, like it or not, are the future (Was: Removing empty directories)

<t89rm6$pna$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5367&group=comp.unix.shell#5367

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: chris@mshome.net (Chris Elvidge)
Newsgroups: comp.unix.shell
Subject: Re: Long options, like it or not, are the future (Was: Removing empty
directories)
Date: Tue, 14 Jun 2022 12:33:10 +0100
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <t89rm6$pna$1@dont-email.me>
References: <t870s4$118f$1@gioia.aioe.org> <t89bfs$pa5$1@gioia.aioe.org>
<20220614110357.4f475343@nx-74205> <t89nhn$1qva$1@gioia.aioe.org>
<t89o6a$1hvrj$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 14 Jun 2022 11:33:26 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="139501e967df3e5b5d20961f0f2091ae";
logging-data="26346"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18WWCbYYK2hndlabny7WRmkZq50KAzQ52c="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101
Thunderbird/52.2.1 Lightning/5.4
Cancel-Lock: sha1:REy/0hc2RW1ZtjVhuFv6NbAvCos=
In-Reply-To: <t89o6a$1hvrj$1@news.xmission.com>
Content-Language: en-GB
 by: Chris Elvidge - Tue, 14 Jun 2022 11:33 UTC

On 14/06/2022 11:33, Kenny McCormack wrote:
> In article <t89nhn$1qva$1@gioia.aioe.org>,
> Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
> ...
>> The schizophrenic thing in this case is that rmdir's other options
>> -v (--verbose), -p (--parents) have short and long form definitions
>> even though the long forms are rather short and easily memorizable
>> but the one with a pathological length (--ignore-fail-on-non-empty,
>> that's five word components!) has no short form. And I still wonder
>> why, what the designers think when doing that. If I'd want users to
>> *not* use a feature or option I'd certainly choose a name like that.
>
> The future trend, like it or not, is towards more and more longer options,
> some, as here, w/o short-form equivalents. I think the general feeling
> among the developer community is that short (one letter) options are
> ambiguous and generally be avoided. They are retained mostly for
> historical compatibility.
>
> A good example of what can go wrong is this: For most programs, most of
> the time, "-v" means "be verbose", which means it is A) generally a good
> idea to include it, and b) safe to do so. But, in the "pkill" command,
> "-v" means (basically) kill everything. Everybody gets bit by this at some
> point in their careers; this is why I think pgrep/pkill should be avoided.
>
> It would be good to have a global, system-wide convention that "-v"
> *always* means "be verbose" - always - and that it is always safe to
> include it on the command line.
>
> Finally, I don't understand your reluctance to use this long option (the 5
> word one), since: A) It does exactly what you want (I was wrong to say
> there was no non-kludgey answer to your question) and B) You are writing a
> script, right?, it is not like you have to type that out interactively.
> Just put it in your script and be done with it.
>

Perhaps log options are the future, but I thought long options were
those introduced by -- rather than - , not that they must be long strings.
What would be wrong with --ifone? Or --ifine (ignore fail if not empty).
-on-non-empty doesn't seem (to me) to be a reasonable language construct.

-v always equals --verbose would be a good idea. -V always being
--version would perhaps also be a good idea?
Would a call to the coreutils guys be in order?

--
Chris Elvidge
England

Re: Long options, like it or not, are the future (Was: Removing empty directories)

<20220614081138.484@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5368&group=comp.unix.shell#5368

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 480-992-1380@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: Long options, like it or not, are the future (Was: Removing
empty directories)
Date: Tue, 14 Jun 2022 15:48:18 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 67
Message-ID: <20220614081138.484@kylheku.com>
References: <t870s4$118f$1@gioia.aioe.org> <t89bfs$pa5$1@gioia.aioe.org>
<20220614110357.4f475343@nx-74205> <t89nhn$1qva$1@gioia.aioe.org>
<t89o6a$1hvrj$1@news.xmission.com>
Injection-Date: Tue, 14 Jun 2022 15:48:18 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="157b33bf86b6f7bf76630a4ae28cffd9";
logging-data="9191"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+o4NJcZE+95KHdChEMTTOowqVaTg9sCvY="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:0Mv4surHsrS1Eji8nRxQd9h/V5s=
 by: Kaz Kylheku - Tue, 14 Jun 2022 15:48 UTC

On 2022-06-14, Kenny McCormack <gazelle@shell.xmission.com> wrote:
> In article <t89nhn$1qva$1@gioia.aioe.org>,
> Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
> ...
>>The schizophrenic thing in this case is that rmdir's other options
>>-v (--verbose), -p (--parents) have short and long form definitions
>>even though the long forms are rather short and easily memorizable
>>but the one with a pathological length (--ignore-fail-on-non-empty,
>>that's five word components!) has no short form. And I still wonder
>>why, what the designers think when doing that. If I'd want users to
>>*not* use a feature or option I'd certainly choose a name like that.
>
> The future trend, like it or not, is towards more and more longer options,
> some, as here, w/o short-form equivalents. I think the general feeling

Maybe there use for medium-form options, you know?

Unix has two and three-letter commands: cat, mv. That is a good
and useful improvement over one-letter commands, and better
than catenate-inputs or rename-or-move-objects.

The problem with --ignore-fail-on-non-empty that it's five words
long.

That's as many words in one option than the number of options GNU rmdir
supports!

How about: before adding two-word options, run out of one-word options.

Oh, and here is something: nonempty is a word, like nontoxic,
nonnegative, nonsense. The Latin prefix non- often doesn't
require a dash, unless it is put on a compound that itself needs
a dash, like "non-age-related".

> among the developer community is that short (one letter) options are
> ambiguous and generally be avoided. They are retained mostly for
> historical compatibility.

Or maybe utility programs that needs more than 20 options want
either to be split into multiple utilities?

A utility program is actually a kind of function, That's why
we speak about arguments.

When the argument options produce a different function,
there is often a good case to give that a different function
name.

In math, a simple option such as a phase shift of 90 degrees
producews a different name

sin(45)

not:

cos(--shift=-90, 45)

The reason this happens in programs is because there is a large
barrier potential working against starting a new program, which has a
lot in common with the exsiting program. It needs more effort, resources
and inevitable duplication.

Using the same program under different names complicates the
installation somewhat; there has to be a step which hard links the
thing, and then you are running into how the program can know its
executable name in the best way under all possible circumstances, which
runs into platform-specific coding.

Re: Long options, like it or not, are the future

<t8abki$dk9$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5369&group=comp.unix.shell#5369

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: dan1espen@gmail.com (Dan Espen)
Newsgroups: comp.unix.shell
Subject: Re: Long options, like it or not, are the future
Date: Tue, 14 Jun 2022 12:05:38 -0400
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <t8abki$dk9$1@dont-email.me>
References: <t870s4$118f$1@gioia.aioe.org> <t89bfs$pa5$1@gioia.aioe.org>
<20220614110357.4f475343@nx-74205> <t89nhn$1qva$1@gioia.aioe.org>
<t89o6a$1hvrj$1@news.xmission.com> <20220614081138.484@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="aba1ff2559323e843875c19c44d80187";
logging-data="13961"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+XdKD2Z7zhATUT28oq4lnCr58l18S3UK8="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:Uoet421Vs2o1seP4G/SCJpuTVjE=
 by: Dan Espen - Tue, 14 Jun 2022 16:05 UTC

Kaz Kylheku <480-992-1380@kylheku.com> writes:

> The problem with --ignore-fail-on-non-empty that it's five words
> long.

Snipped the rest of the post where you didn't even try to prove that 5
words is a problem. As it is, the rarely used option explains itself.
If I encountered it in a script I'd know exactly what it does.

But more important, I've found it a good policy NOT to criticize the
work of others until I've done better.

--
Dan Espen

Re: Removing empty directories

<20220614084855.271@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5370&group=comp.unix.shell#5370

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 480-992-1380@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: Removing empty directories
Date: Tue, 14 Jun 2022 16:27:34 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 71
Message-ID: <20220614084855.271@kylheku.com>
References: <t870s4$118f$1@gioia.aioe.org> <875yl4n2ik.fsf@bsb.me.uk>
Injection-Date: Tue, 14 Jun 2022 16:27:34 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="157b33bf86b6f7bf76630a4ae28cffd9";
logging-data="26887"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+utucxATJAblqRL9qpN3H4y3iAJVKN9cw="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:FWaJZwlkBxJMRkC2m0PplHCmGBo=
 by: Kaz Kylheku - Tue, 14 Jun 2022 16:27 UTC

On 2022-06-13, Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
> Janis Papanagnou <janis_papanagnou@hotmail.com> writes:
>
>> Is there some elegant way to test/remove an empty directory?
>>
>> Currently I am unconditionally doing rmdir "$dir" 2>/dev/null
>> where an empty directory will be removed, and the error message
>> in case of non-empty directories suppressed. It works, but that
>> way I suppress all error information which might have undesired
>> or undetected bad effects.
>
> Depending on what rmdir you have, and what your portability requirements
> are, you might find that
>
> rmdir --ignore-fail-on-non-empty "$dir"
>
> does what you want.

This option is next to useless; all it does is prevent an unsuccesful
termination status of rmdir due to nonempty directories.

Both these commands will have the same effect on the file system:

rmdir empty1 empty2 nonempty empty3

rmdir --ignore-fail-on-nonempty empty1 empty2 nonempty empty3

the first one will have a failed termination status due to not
having removced nonempty.

But the refusal to remove nonempty is just a technical/historic
limitation in the first place. It comes from, roughly this:

1. There is a primitive system call which (for good reasons)
is restricted to removing a directory, which is empty.
The good reason for this is that the operation must be
implemented multiple times for different kinds of filesystems.
Whereas a recursive removal can be implemented in a higher
layer, independently of filesystems.

2. For historic reasons, the primitive system call was mirrored
in a rmdir utility which is more or less just a wrapper
for it (except for the -p feature it begat).

3. The "remove anything, including recursively" functionality
became the domain of the "rm" command, and so the
requirements for "rmdir" have not been maintained
in that direction.

When I'm doing this:

rmdir empty1 empty2 nonempty empty3

I almost always want all four directories to just be gone.
In other words, I want

rm -r(f) empty1 empty2 nonempty empty3

Now maybe if they cannot all be gone, the *ideal* behavior for
rmdir would be to do nothing: fail and do not touch the filesystem.
Yet, I would want that to happen for some real reason not
because some directory is nonempty.

The that there is a primitive rmdir operation in the kernel's VFS layer
that doesn't work on nonempty directories is completely irrelevant to
what I'm doing. It's annoying implementation level fluff, exactly like
Windows refusing to delete a file that's open in some application.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Re: Long options, like it or not, are the future

<20220614092805.136@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5371&group=comp.unix.shell#5371

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 480-992-1380@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: Long options, like it or not, are the future
Date: Tue, 14 Jun 2022 16:50:40 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 64
Message-ID: <20220614092805.136@kylheku.com>
References: <t870s4$118f$1@gioia.aioe.org> <t89bfs$pa5$1@gioia.aioe.org>
<20220614110357.4f475343@nx-74205> <t89nhn$1qva$1@gioia.aioe.org>
<t89o6a$1hvrj$1@news.xmission.com> <20220614081138.484@kylheku.com>
<t8abki$dk9$1@dont-email.me>
Injection-Date: Tue, 14 Jun 2022 16:50:40 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="157b33bf86b6f7bf76630a4ae28cffd9";
logging-data="4559"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+cTzQ/n8+5B7uuCfRzCvZTHx2alg9jlVo="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:EyJFl+W2J+DQQoJB740QbQAEfVY=
 by: Kaz Kylheku - Tue, 14 Jun 2022 16:50 UTC

On 2022-06-14, Dan Espen <dan1espen@gmail.com> wrote:
> Kaz Kylheku <480-992-1380@kylheku.com> writes:
>
>> The problem with --ignore-fail-on-non-empty that it's five words
>> long.
>
> Snipped the rest of the post where you didn't even try to prove that 5
> words is a problem. As it is, the rarely used option explains itself.

It doesn't explain itself.

> If I encountered it in a script I'd know exactly what it does.

I had to look it up and experiment with it, and also rely on other
documentation (POSIX). My first blind guess was: does it actually delete
the nonempty directory, like rm -r? But no, that couldn't be it;
that's significantly more than what "ignore" means.

So my next suspicion was: ok, so if ignoring that situation is
not the default behavior, it might be that rmdir *heeds* the situation
somehow. Maybe it's deleting the directories in left-to-right
order and then failing on the first nonempty directory,
so the rest are unprocessed.

But in fact, ignore just means "ignore for the purposes of calculating
the termination status", not for the purposes of any action.

To be sure about this, I had to experiment. Neither the man nor the info
page explains what it means to ignore or not to ignore the error.
Before that, I also looked at the POSIX documentation, which which
assures us that rmdir invokes the rmdir system call for each argument.

The POSIX documentation also has this:

EXIT STATUS:

The following exit values shall be returned:

0
Each directory entry specified by a dir operand was removed
successfully.
>0
An error occurred.

We know that since the rmdir system call is used, ENOTEMPTY is an error;
so we know that if one or more directories were not deleted due to not
being empty, and all others were deleted, there will be a failed status.

The GNU documentation says only this (in the info page, not the man
page):

An exit status of zero indicates success, and a nonzero value
indicates failure.

which is just teaching the reader how exist status works in a POSIX-like
system, not what it means for this particular command.

After looking at the POSIX documentation, I inferred that "ignore" must
just mean mean not to to include that situation in the exit status,
after which a quick experiment confirmed it.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Re: Long options, like it or not, are the future (Was: Removing empty directories)

<t8ai4v$6d5$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5372&group=comp.unix.shell#5372

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!tg95bLwDfWQ+I1oAs1xdEw.user.46.165.242.75.POSTED!not-for-mail
From: janis_papanagnou@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Long options, like it or not, are the future (Was: Removing empty
directories)
Date: Tue, 14 Jun 2022 19:56:47 +0200
Organization: Aioe.org NNTP Server
Message-ID: <t8ai4v$6d5$1@gioia.aioe.org>
References: <t870s4$118f$1@gioia.aioe.org> <t89bfs$pa5$1@gioia.aioe.org>
<20220614110357.4f475343@nx-74205> <t89nhn$1qva$1@gioia.aioe.org>
<t89o6a$1hvrj$1@news.xmission.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="6565"; posting-host="tg95bLwDfWQ+I1oAs1xdEw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Janis Papanagnou - Tue, 14 Jun 2022 17:56 UTC

On 14.06.22 12:33, Kenny McCormack wrote:
> In article <t89nhn$1qva$1@gioia.aioe.org>,
> Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
> ...
>> The schizophrenic thing in this case is that rmdir's other options
>> -v (--verbose), -p (--parents) have short and long form definitions
>> even though the long forms are rather short and easily memorizable
>> but the one with a pathological length (--ignore-fail-on-non-empty,
>> that's five word components!) has no short form. And I still wonder
>> why, what the designers think when doing that. If I'd want users to
>> *not* use a feature or option I'd certainly choose a name like that.
>
> The future trend, like it or not, is towards more and more longer
options,
> some, as here, w/o short-form equivalents. I think the general feeling
> among the developer community is that short (one letter) options are
> ambiguous and generally be avoided. They are retained mostly for
> historical compatibility.

There's nothing wrong in supporting long options [in addition to the
short ones]. It's sort of a in-code documentation that we observe in
many programming languages (Java comes to mind, specifically), mainly
where [arbitrary] user entities are introduced; variables, functions,
classes, packages, etc. In such languages we have IDEs that provide
us with the feature to get lists of names we can simply choose from,
though, we don't look them up or type them any more.

Unix commands are not quite comparable, since it's a toolbox, more
like (but not exactly) the underlying operating language. It has at
least a stability factor (as opposed to user defined entities), as
we can derive from the long time standardization efforts.

My question about the "Why?" - which, frankly, isn't addressed by
pointing to a "future trend" - stems from practical considerations,
how shell programs are regularly developed and used. The whole mess
could probably be best described by a (fictional) command like this:
list-filesystem-item --display-in-long-format --sort-by-time \
--order-is-oldest-first
in case it's not obvious, this is something like the commonly used
'ls -ltr', and it resembles more the commands of a TR 440 computer
from the mid of the last century than anything modern (and even the
TR 440 operating system allowed command abbreviations, if I recall
correctly; i.e. the "trend" at that time was to make things usable).

>
> A good example of what can go wrong is this: For most programs, most of
> the time, "-v" means "be verbose", which means it is A) generally a good
> idea to include it, and b) safe to do so. But, in the "pkill" command,
> "-v" means (basically) kill everything. Everybody gets bit by this
at some
> point in their careers; this is why I think pgrep/pkill should be
avoided.

I completely agree that the choice of option names is not (or rather
can not be) coherent across the many existing Unix tools. But that's
another point, and the question is; what to do design-wise to address
legibility - ideally without sacrificing the advantages of short form
options. The path taken was the introduction of long options; and to
repeat myself, that's a good thing. (But doesn't adress the question
why there's no short option.)

>
> It would be good to have a global, system-wide convention that "-v"
> *always* means "be verbose" - always - and that it is always safe to
> include it on the command line.

For a subset of common options that would be good, I agree. (But that's
again independent of introducing long option names.)

There's also other, additional possibilities to address the flood of
(different) option names. We could avoid defining specific functions
by options; 'ls' or 'ps' comes to my mind. We could replace options
that are only defining (output-)format by format options (AIX's ps -o
as an example), which has meanwhile found its way into some commands.

>
> Finally, I don't understand your reluctance to use this long option
(the 5
> word one), since: A) It does exactly what you want (I was wrong to say
> there was no non-kludgey answer to your question) and B) You are
writing a
> script, right?, it is not like you have to type that out interactively.
> Just put it in your script and be done with it.

I was looking for an "elegant" solution. My reluctance stems from the
fact that a programmed [kludgy] workaround (using even perl, awk, sh
one-liners) would not be larger (character-count-wise) than the length
of that option name.

Yes, I can copy/paste that option-"sentence" and put that in my script.
But I think it is nonetheless a valid question I asked; why there's
no short form available. (And why "trendy" designers do what they've
done, since there's yet a rationale missing why they are thinking that
the 1950's way of OS-language design would be sensible in this case.)

For my day-to-day use of the shell language I don't want to look up
whether the option was "--order-is-oldest-first", "--oldest-first",
"--order-by-oldest-first", or whatever; I clearly prefer '-t' when
typing the 'list-filesystem-item', erm.., the 'ls' command.

Janis

Re: Long options, like it or not, are the future

<t8aiqe$4q0$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5373&group=comp.unix.shell#5373

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: dan1espen@gmail.com (Dan Espen)
Newsgroups: comp.unix.shell
Subject: Re: Long options, like it or not, are the future
Date: Tue, 14 Jun 2022 14:08:14 -0400
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <t8aiqe$4q0$1@dont-email.me>
References: <t870s4$118f$1@gioia.aioe.org> <t89bfs$pa5$1@gioia.aioe.org>
<20220614110357.4f475343@nx-74205> <t89nhn$1qva$1@gioia.aioe.org>
<t89o6a$1hvrj$1@news.xmission.com> <20220614081138.484@kylheku.com>
<t8abki$dk9$1@dont-email.me> <20220614092805.136@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="aba1ff2559323e843875c19c44d80187";
logging-data="4928"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+kdmFwwRNWemyg4z7h1MZEm03ir5T4SSQ="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:4S5QOmi9GW7IU9y+Gjuk1/Il3EE=
 by: Dan Espen - Tue, 14 Jun 2022 18:08 UTC

Kaz Kylheku <480-992-1380@kylheku.com> writes:

> On 2022-06-14, Dan Espen <dan1espen@gmail.com> wrote:
>> Kaz Kylheku <480-992-1380@kylheku.com> writes:
>>
>>> The problem with --ignore-fail-on-non-empty that it's five words
>>> long.
>>
>> Snipped the rest of the post where you didn't even try to prove that 5
>> words is a problem. As it is, the rarely used option explains itself.
>
> It doesn't explain itself.
>
>> If I encountered it in a script I'd know exactly what it does.
>
> I had to look it up and experiment with it, and also rely on other
> documentation (POSIX). My first blind guess was: does it actually delete
> the nonempty directory, like rm -r? But no, that couldn't be it;
> that's significantly more than what "ignore" means.

Okay maybe not a 100% explanation but it sure tells you a whole lot more
than a 1 letter option or -ign-rmdir-fail.

And you still haven't identified a problem with a long -- option.

--
Dan Espen

Re: Removing empty directories

<83r13r7yv3.fsf@helmutwaitzmann.news.arcor.de>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5374&group=comp.unix.shell#5374

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!5zbID3I7J9d2hObGz2DhcQ.user.46.165.242.75.POSTED!not-for-mail
From: nn.throttle@xoxy.net (Helmut Waitzmann)
Newsgroups: comp.unix.shell
Subject: Re: Removing empty directories
Date: Tue, 14 Jun 2022 22:51:12 +0200
Organization: Aioe.org NNTP Server
Message-ID: <83r13r7yv3.fsf@helmutwaitzmann.news.arcor.de>
References: <t870s4$118f$1@gioia.aioe.org> <20220613052944.117@kylheku.com>
Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: quoted-printable
Injection-Info: gioia.aioe.org; logging-data="27161"; posting-host="5zbID3I7J9d2hObGz2DhcQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)
Mail-Copies-To: nobody
Cancel-Lock: sha1:ERMas9pivom+2EolmJEtfz97dqk=
Mail-Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
X-Notice: Filtered by postfilter v. 0.9.2
 by: Helmut Waitzmann - Tue, 14 Jun 2022 20:51 UTC

Kaz Kylheku <480-992-1380@kylheku.com>:
>On 2022-06-13, Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
>
>> The rmdir(1) command is delegated to the rmdir(2) system call.
>> What would rmdir(2) do to determine the emptiness?
>
>I believe rmdir must be a dedicated primitive in each filesystem
>implementation, including checking the necessary criteria.

[…]

>> Would we have to do something similar/complex or am I missing
>> something obvious?
>
>GNU find has an -empty directive. This actually opens the
>directory, and reads it until it finds an entry which is neither
>"." nor "..". I suspect that is the only way which approaches 100%
>portability across filesystems.

Using a "find" utility that is compliant with the POSIX standard,
the shell function – I think –

is_non-empty_dir()
(
${1:+:} false &&
! test -L "$1" &&
test -d "$1" &&
test -r "$1" &&
unset -v -- findsafe &&
case "$1" in
(/*) findsafe="$1" ;;
(*) findsafe=./"$1" ;;
esac &&
{
printf '%s\n' false &&
find "${findsafe%/}"/ \
! -path '*/' \( -prune -o ! -prune \) \
-exec printf '%s\n' 'exit 0' \; 2> /dev/null
} | sh
)

should test for a readable non‐empty directory.  That can be used to
protect "rmdir" from being invoked with a readable non‐empty
directory:

if ! is_non-empty_dir "$dir"
then
rmdir -- "$dir"
fi

Remark: The directory to be removed by the "rmdir" command i. e. by
the "rmdir()" system call doesn't need to be readable. 
Unfortunately, the invocation of the find utility in the shell
function "is_non-empty_dir" above needs the directory to be readable
else it cannot tell whether the directory is empty or non‐empty.  To
be safe it regards any unreadable directory as being empty (thus let
"rmdir" check by itself).

There is a race condition, of course.  Therefore there really is no
safe alternative to the "--ignore-fail-on-non-empty" option of the
GNU "rmdir" command.

Re: Long options, like it or not, are the future

<20220614134949.769@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5375&group=comp.unix.shell#5375

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 480-992-1380@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: Long options, like it or not, are the future
Date: Tue, 14 Jun 2022 21:30:46 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <20220614134949.769@kylheku.com>
References: <t870s4$118f$1@gioia.aioe.org> <t89bfs$pa5$1@gioia.aioe.org>
<20220614110357.4f475343@nx-74205> <t89nhn$1qva$1@gioia.aioe.org>
<t89o6a$1hvrj$1@news.xmission.com> <20220614081138.484@kylheku.com>
<t8abki$dk9$1@dont-email.me> <20220614092805.136@kylheku.com>
<t8aiqe$4q0$1@dont-email.me>
Injection-Date: Tue, 14 Jun 2022 21:30:46 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="157b33bf86b6f7bf76630a4ae28cffd9";
logging-data="313"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+fKLRusnf/tk5bqUh1lNdhfZjLhN02lO0="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:lXrR7S3/dSadie/EUyWMNOKAFR8=
 by: Kaz Kylheku - Tue, 14 Jun 2022 21:30 UTC

On 2022-06-14, Dan Espen <dan1espen@gmail.com> wrote:
> Kaz Kylheku <480-992-1380@kylheku.com> writes:
>
>> On 2022-06-14, Dan Espen <dan1espen@gmail.com> wrote:
>>> Kaz Kylheku <480-992-1380@kylheku.com> writes:
>>>
>>>> The problem with --ignore-fail-on-non-empty that it's five words
>>>> long.
>>>
>>> Snipped the rest of the post where you didn't even try to prove that 5
>>> words is a problem. As it is, the rarely used option explains itself.
>>
>> It doesn't explain itself.
>>
>>> If I encountered it in a script I'd know exactly what it does.
>>
>> I had to look it up and experiment with it, and also rely on other
>> documentation (POSIX). My first blind guess was: does it actually delete
>> the nonempty directory, like rm -r? But no, that couldn't be it;
>> that's significantly more than what "ignore" means.
>
> Okay maybe not a 100% explanation but it sure tells you a whole lot more
> than a 1 letter option or -ign-rmdir-fail.

Well, ign-rmdir-fails lies, because not not every kind of failure from
rmdir is ignored.

I would not have expended more effort to find out what it does
if the GNU option had been called --fzi, but at least less eye effort to
read it, and finger effort to type it.

How about:

--sne "Skip not empty"

Effectively, skip directories which are not empty.
Deletion is still tried for all directory arguments;
but failure to delete a directory due to it being
nonempty is not reflected in the termination status.

The command itself has a short name: "remove directory" is condensed
to "rmdir".

If "stream editor" can become "sed", why can't "skip not empty"
become "sne"?

The nice thing about --sne is that when you don't know what that
means, you *know* that you don't know; you look it up. But it's
not just a random clump of letters like --fzi; it has mnemonic value.
It's unlikely you will ever have to look it up more than twice.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Re: Removing empty directories

<t8b24v$74j$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=5376&group=comp.unix.shell#5376

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: lew.pitcher@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.shell
Subject: Re: Removing empty directories
Date: Tue, 14 Jun 2022 22:29:51 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <t8b24v$74j$1@dont-email.me>
References: <t870s4$118f$1@gioia.aioe.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 14 Jun 2022 22:29:51 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="9f7aa118d912f3ec32e3668b19b7c3bb";
logging-data="7315"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+IC8EmW6sXaWAUmUxyu5mcVJdQcXwWgMI="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:T/Axu8tvUoUl5/O5gsC6INOq3nA=
 by: Lew Pitcher - Tue, 14 Jun 2022 22:29 UTC

On Mon, 13 Jun 2022 11:43:31 +0200, Janis Papanagnou wrote:

> Is there some elegant way to test/remove an empty directory?
>
> Currently I am unconditionally doing rmdir "$dir" 2>/dev/null where an
> empty directory will be removed, and the error message in case of
> non-empty directories suppressed. It works, but that way I suppress all
> error information which might have undesired or undetected bad effects.
> So I was looking for some test based approach like [[...]] && rmdir
> "$dir" but couldn't find simple tests for that (e.g. -d and link count
> comparison isn't really elegant either, the same with something like ls
> .* * 2>/dev/null and string comparisons, or similar).
>
> The rmdir(1) command is delegated to the rmdir(2) system call. What
> would rmdir(2) do to determine the emptiness? Would we have to do
> something similar/complex or am I missing something obvious?
>
> Janis

With a two-stage delete, you have to be aware of the possible race
conditions (what is now, colloqually, known as "toctoa" or "time of
check to time of use"). A external file create may occur in the interval
between the time that the check pronounces the directory "empty" and the
delete attempts to delete it. Similarly, an external file delete that
empties the directory may occur immediately after the check pronounces
the directory "not empty". None of the two-stage delete processes, either
by script, or by utility (like find(1)) accommodate this situation.

However, even though it is not "pretty", the rmdir(2) call (and the
rmdir(1) utility) perform an atomic test-and-delete. Your best bet, IMHO,
is to suppress the rmdir(1) error reporting (such as has been suggested
with the GNU rmdir(1) --ignore-fail-on-non-empty option) and cope with
the inelegance of the solution. The alternatives are worse.

--
Lew Pitcher
"In Skills, We Trust"

Pages:123
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor