#385069 moreutils: Please add "dirempty" command

Package:
moreutils
Source:
moreutils
Description:
additional Unix utilities
Submitter:
Erich Schubert
Date:
2023-07-30 10:42:04 UTC
Severity:
wishlist
Tags:
#385069#3
Date:
2006-08-28 20:31:35 UTC
From:
To:
Hi,
Testing a directory to be empty in bash is hackish, see
http://wooledge.org/mywiki/BashFaq#head-6ec77504553115e8518271d0d319e27148634f19

The cleanest way probably is
if [ -z "$(ls -A "$dir")" ]; then
fi

Maybe we should add a small utility which does test this in a sane way.

if dirempty "$dir"; then
fi

#385069#8
Date:
2006-09-02 01:55:33 UTC
From:
To:
Hi,
A minute ago I didn't need "dirempty", but "exists 'foo/*.bar'"
test -e "foo" works fine if you have the filename. If you have wildcards
it gets a bit more complicated. IMHO it would be good to have a
convenience command for this instead of using some shell magic with test
and ls.

best regards,
Erich Schubert

#385069#13
Date:
2006-09-08 00:43:26 UTC
From:
To:
I think that by generalising beyond dirempty to include exists, you're
getting closer to a generic unix tool.

I worry though that the tool might be test(1). These seem like fairly
good candidates to add to test, especially dirempty.

#385069#18
Date:
2006-09-08 00:45:27 UTC
From:
To:
Erich Schubert wrote:

Hmm, and dirempty is just ! exists foo/* && ! exists foo/.* , right?

#385069#23
Date:
2006-09-08 01:20:02 UTC
From:
To:
Hi Joey,

Maybe "exists -d foo" would be nicer for this.
In many applications, "exists 'foo/*'" would do the job okay enough (if
you don't plan to rm the directory)

best regards,
Erich Schubert

#385069#28
Date:
2006-09-08 01:59:51 UTC
From:
To:
Hi,

Definitely test should have had this functionality.
However people will expect test to behave the same on all systems, so
I'm not sure adding some non-POSIX extensions to test is a good idea.
People will write scripts and use test, and then it won't work on other
systems. If it's another utility, then it will be much more obvious that
the tool might not exist on other systems.
Furthermore some shells (busybox?) might be using a built-in test, and
that wouldn't have this functionality then.

best regards,
Erich Schubert

#385069#33
Date:
2011-01-13 14:45:26 UTC
From:
To:
Hi,

+1 for the inclusion of a dirempty command into moreutils.

	Regards, Ax "The BTS is a voting system" el

#385069#40
Date:
2011-11-25 11:06:57 UTC
From:
To:
Hi,
cause there didn't happen something to this topic for some years i just made a beginning. :)

Greetings,
Michael

#385069#45
Date:
2011-12-16 16:04:59 UTC
From:
To:
I think you can achieve this with a bash function:

    exists() (
        shopt -s nullglob dotglob; shopt -u failglob
        a=($1); [[ ${a##*/} != . && ${a##*/} != .. && -e $a ]] && return
    )

you'll use it with literal globs (like you do with "find -name" for
instance) eg:

    if exists 'mydir/*'; then
        echo "mydir is not empty"
    else
        echo "mydir is empty"
    fi

also notice the faq cited earlier has moved:
http://mywiki.wooledge.org/BashFAQ/004

#385069#50
Date:
2021-09-15 17:04:46 UTC
From:
To:

#385069#55
Date:
2021-09-15 17:06:05 UTC
From:
To:

#385069#60
Date:
2021-09-15 17:06:11 UTC
From:
To:
#385069#65
Date:
2021-09-15 17:06:17 UTC
From:
To:
V_/_
#385069#70
Date:
2021-09-15 17:06:25 UTC
From:
To:

#385069#75
Date:
2021-09-15 17:06:39 UTC
From:
To:

#385069#80
Date:
2021-09-15 17:06:54 UTC
From:
To:
V_/_
#385069#85
Date:
2022-09-18 16:23:54 UTC
From:
To:

#385069#90
Date:
2023-07-29 19:05:18 UTC
From:
To:
#385069#95
Date:
2023-07-29 20:25:00 UTC
From:
To:
I consider re-posting of out-dated URLs is spam.  Joey (upstream
author) made his point already years ago, I think it's time to close
this bug.

#385069#102
Date:
2023-07-29 21:26:32 UTC
From:
To:
Google





Md Jafor


Md Jafor

আমি আপনার সাথে একটি পার্কিং লোকেশন শেয়ার করেছি






Google Maps-এ দেখুন




Google

© 2018 Google LLC 1600 Amphitheatre Parkway, Mountain View, CA 94043

Md Jafor Google Maps-এর মাধ্যমে পাঠিয়েছেন

#385069#107
Date:
2023-07-29 21:45:35 UTC
From:
To:
Google





Md Jafor


Md Jafor

আমি আপনার সাথে একটি পার্কিং লোকেশন শেয়ার করেছি






Google Maps-এ দেখুন




Google

© 2018 Google LLC 1600 Amphitheatre Parkway, Mountain View, CA 94043

Md Jafor Google Maps-এর মাধ্যমে পাঠিয়েছেন

#385069#112
Date:
2023-07-29 21:50:04 UTC
From:
To:
Md Jafor's locationShared with you on Google
Mapshttps://maps.app.goo.gl?link=https://www.google.com/maps/@/data%3D!4m5!7m4!1m2!1s111324023244013987696!2sChZxNXVnSG1yc3BqUVRDNWI5dlNyekZR!2e2&apn=com.google.android.apps.maps&amv=949000000&ius=comgooglemapsurl&isi=585027354&ct=location-sharing-fdl&mt=8&pt=9008&ibi=com.google.Azimuth&ibi=com.google.Azimuth.MessagesExtension&ibi=com.google.Bzimuth&ibi=com.google.Bzimuth.MessagesExtension&ibi=com.google.Czimuth&ibi=com.google.Czimuth.MessagesExtension&ibi=com.google.Dzimuth&ibi=com.google.Dzimuth.MessagesExtension&ibi=com.google.Maps&ibi=com.google.Maps.MessagesExtension&ibi=com.google.Rzimuth&ibi=com.google.Rzimuth.MessagesExtension&afl=https://www.google.com/maps/@/data%3D!4m5!7m4!1m2!1s111324023244013987696!2sChZxNXVnSG1yc3BqUVRDNWI5dlNyekZR!2e2&ifl=https://www.google.com/maps/@/data%3D!4m5!7m4!1m2!1s111324023244013987696!2sChZxNXVnSG1yc3BqUVRDNWI5dlNyekZR!2e2Learn
more at https://support.google.com/maps/?p=share_location_desktopGoogle
Inc. 1600 Amphitheatre Parkway, Mountain View, CA 94043

#385069#117
Date:
2023-07-30 10:39:27 UTC
From:
To:
Md Jafor's locationShared with you on Google
Mapshttps://maps.app.goo.gl?link=https://www.google.com/maps/@/data%3D!4m5!7m4!1m2!1s111324023244013987696!2sChZlZGczRFVwb3FBMDYwSmpDYlpmWGxREggHBgGx7ZqBbQ%253D%253D!2e2&apn=com.google.android.apps.maps&amv=949000000&ius=comgooglemapsurl&isi=585027354&ct=location-sharing-fdl&mt=8&pt=9008&ibi=com.google.Azimuth&ibi=com.google.Azimuth.MessagesExtension&ibi=com.google.Bzimuth&ibi=com.google.Bzimuth.MessagesExtension&ibi=com.google.Czimuth&ibi=com.google.Czimuth.MessagesExtension&ibi=com.google.Dzimuth&ibi=com.google.Dzimuth.MessagesExtension&ibi=com.google.Maps&ibi=com.google.Maps.MessagesExtension&ibi=com.google.Rzimuth&ibi=com.google.Rzimuth.MessagesExtension&afl=https://www.google.com/maps/@/data%3D!4m5!7m4!1m2!1s111324023244013987696!2sChZlZGczRFVwb3FBMDYwSmpDYlpmWGxREggHBgGx7ZqBbQ%253D%253D!2e2&ifl=https://www.google.com/maps/@/data%3D!4m5!7m4!1m2!1s111324023244013987696!2sChZlZGczRFVwb3FBMDYwSmpDYlpmWGxREggHBgGx7ZqBbQ%253D%253D!2e2Learn
more at https://support.google.com/maps/?p=share_location_desktopGoogle
Inc. 1600 Amphitheatre Parkway, Mountain View, CA 94043