From unknown Mon Jun 23 07:48:55 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#21218 <21218@debbugs.gnu.org> To: bug#21218 <21218@debbugs.gnu.org> Subject: Status: ls -d Reply-To: bug#21218 <21218@debbugs.gnu.org> Date: Mon, 23 Jun 2025 14:48:55 +0000 retitle 21218 ls -d reassign 21218 coreutils submitter 21218 "Sneeh, Eddie" severity 21218 normal tag 21218 notabug thanks From debbugs-submit-bounces@debbugs.gnu.org Fri Aug 07 20:13:19 2015 Received: (at submit) by debbugs.gnu.org; 8 Aug 2015 00:13:19 +0000 Received: from localhost ([127.0.0.1]:50494 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZNrlH-0005xR-32 for submit@debbugs.gnu.org; Fri, 07 Aug 2015 20:13:19 -0400 Received: from eggs.gnu.org ([208.118.235.92]:42097) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZNraL-0005dV-Aq for submit@debbugs.gnu.org; Fri, 07 Aug 2015 20:02:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZNraF-0003Q4-4y for submit@debbugs.gnu.org; Fri, 07 Aug 2015 20:01:55 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,HTML_MESSAGE autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:35455) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZNraF-0003Q0-1b for submit@debbugs.gnu.org; Fri, 07 Aug 2015 20:01:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55595) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZNraD-0006bs-Kv for bug-coreutils@gnu.org; Fri, 07 Aug 2015 20:01:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZNra9-0003Pm-Kg for bug-coreutils@gnu.org; Fri, 07 Aug 2015 20:01:53 -0400 Received: from mailgate1.roche.com ([196.3.50.140]:56541) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZNra9-0003Pe-CO for bug-coreutils@gnu.org; Fri, 07 Aug 2015 20:01:49 -0400 Received: from 145.245.200.230 (EHLO mg-int1.roche.com) ([145.245.200.230]) by mailgate1.roche.com (MOS 4.4.4-GA FastPath queued) with ESMTP id AFY42244; Sat, 08 Aug 2015 02:01:46 +0200 (CEST) Received: from 196.3.47.253 (EHLO mail-wi0-f178.google.com) ([196.3.47.253]) by mg-int1.roche.com (MOS 4.4.4-GA FastPath queued) with ESMTP id DIL98415; Sat, 08 Aug 2015 02:01:46 +0200 (CEST) Received: by mail-wi0-f178.google.com with SMTP id p15so76482219wij.0 for ; Fri, 07 Aug 2015 17:01:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to :content-type; bh=WUt4ckcCgOSU9C7AhLoQQO1AWRxHopoys8b+XDZFNdQ=; b=kAws9/p6h0QY5uHTd6O91SomzL5irOToHsr5BMuPoE1Ad3JhDRgVGY5aPuvP13hJjF QL2tY4C9VV45ILHQU+HfARfcVIKYyyl0GYREdYs5ytDEJsTOc+PK+6X7ttWTmFvXQDCK d1ylzUvLim3YONdt27fX6PM9Bf0HOJ73QcoQyYZqpBBaSMVQrK6rumyyiRyFKx5Y3AMp /kQe9aBIYhjT+ep1/lI8VMTNLV/yp2AqWUeih70slFvAZ/whf/bb59G++tJ1GP8ZMgVs FbIMQgYL/x/wCC+2jU83+raFHw9qe/xorozJZ0FLIOztygSlOBeBYKCzCiqaRNglC5Ks c6KQ== X-Gm-Message-State: ALoCoQmN3xe16cGtWKK8uw/TXZtXdU+Fne7zAraSTvQh5OYU9zONKUw+jja234ol5Qkre4DEbgcAtRAPPc9IhEy7wwUhcc16dnffydnWm1rLpa7SadMxtRORCXRS2gpgwTsFoYWqOxa8 X-Received: by 10.194.191.164 with SMTP id gz4mr20165203wjc.21.1438992106105; Fri, 07 Aug 2015 17:01:46 -0700 (PDT) X-Received: by 10.194.191.164 with SMTP id gz4mr20165157wjc.21.1438992105679; Fri, 07 Aug 2015 17:01:45 -0700 (PDT) MIME-Version: 1.0 Received: by 10.27.214.72 with HTTP; Fri, 7 Aug 2015 17:01:06 -0700 (PDT) From: "Sneeh, Eddie" Date: Fri, 7 Aug 2015 17:01:06 -0700 Message-ID: Subject: ls -d To: bug-coreutils@gnu.org Content-Type: multipart/alternative; boundary=047d7ba982124b4c29051cc1756f X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.3 (----) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Fri, 07 Aug 2015 20:13:18 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.3 (----) --047d7ba982124b4c29051cc1756f Content-Type: text/plain; charset=UTF-8 Hi, I believe there is a problem with ls -d (unless the intent is to just list 1 directory). Say I have a dir mydir, it has directories d1 and d2, and files f1 and f2. I want to list only d1 and d2. How do I do that? I tried ls -d but that doesn't seem to work: \ls -d mydir returns: mydir \ls -d mydir/* returns: mydir/d1 mydir/d2 mydir/f1 mydir/f2 but f1 and f2 are files. How can I achieve the following: \ls ?????? mydir to return: mydir/d1 mydir/d2 -- Best Regards, *Eddie Sneeh* --047d7ba982124b4c29051cc1756f Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi,
I believe there is a problem with ls -d (unless the intent is= to just list 1 directory).
Say I have a dir mydir, it has directories d1 an= d d2, and files f1 and f2.
I want to list only d1 and d2.=C2=A0 How do I do = that?=C2=A0 I tried ls -d but that doesn't seem to work:
\ls -d mydir
ret= urns: mydir
\ls -d mydir/*
returns: mydir/d1 mydir/d2 mydir/f1 mydir/f2
=
but f1= and f2 are files.

How can I achieve the following:
\ls ?????? mydir
to re= turn: mydir/d1 mydir/d2



--
Best Regards,
Eddie Sneeh
--047d7ba982124b4c29051cc1756f-- From debbugs-submit-bounces@debbugs.gnu.org Fri Aug 07 23:43:47 2015 Received: (at control) by debbugs.gnu.org; 8 Aug 2015 03:43:47 +0000 Received: from localhost ([127.0.0.1]:50513 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZNv2x-00035n-DU for submit@debbugs.gnu.org; Fri, 07 Aug 2015 23:43:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39098) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZNv2u-00035Z-Ct; Fri, 07 Aug 2015 23:43: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 (Postfix) with ESMTPS id 44AB48C1B6; Sat, 8 Aug 2015 03:43:43 +0000 (UTC) Received: from [10.3.113.187] (ovpn-113-187.phx2.redhat.com [10.3.113.187]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t783hgKo016747; Fri, 7 Aug 2015 23:43:42 -0400 Subject: Re: bug#21218: ls -d To: "Sneeh, Eddie" , 21218-done@debbugs.gnu.org References: From: Eric Blake Openpgp: url=http://people.redhat.com/eblake/eblake.gpg Organization: Red Hat, Inc. Message-ID: <55C57AE2.1010803@redhat.com> Date: Fri, 7 Aug 2015 21:43:30 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="9dIfJ6BqUNshnNWvw7SVGbh00P5PfGmUB" X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Spam-Score: -5.1 (-----) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.1 (-----) This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --9dIfJ6BqUNshnNWvw7SVGbh00P5PfGmUB Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable tag 21218 notabug thanks On 08/07/2015 06:01 PM, Sneeh, Eddie wrote: > Hi, > I believe there is a problem with ls -d (unless the intent is to just l= ist > 1 directory). Thanks for the report. However, I think you have misunderstood the purpose of -d. Try this for comparison: touch file ls . file ls -d . file All -d does is to list command line arguments that are directories as the name of the directory itself, rather than descending and showing the directory's contents. > Say I have a dir mydir, it has directories d1 and d2, and files f1 and = f2. > I want to list only d1 and d2. How do I do that? I tried ls -d but th= at > doesn't seem to work: > \ls -d mydir > returns: mydir > \ls -d mydir/* > returns: mydir/d1 mydir/d2 mydir/f1 mydir/f2 > but f1 and f2 are files. If you want to list ONLY directories, use a glob that guarantees only directories can be matched: ls -d mydir/*/ The trailing slash can only match directories, and will therefore skip ordinary files. Or, you can use find: find mydir -mindepth 1 -maxdepth 2 -type d I'm closing this as not a bug as ls is working as designed, but feel free to ask further questions. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --9dIfJ6BqUNshnNWvw7SVGbh00P5PfGmUB Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJVxXriAAoJEKeha0olJ0Nq7zkH/3WY4Kh/AfGArUFoBixj1e8m UbJTHqYUH14JlxLmtR3025lMRIGtEyakg7aPjITzAoWZwm75E9LbIfH9ANwhPkrd Q6fyenkAH4t4iT1+ysDalvjL1GQnyjoFZTPFzgrfiR3iX1AOuxaUsoUosM1mLB3x 6UYvIGmdzi8LY04RvmDPFGsXG3P4MO5We29st2MOsRPxxKDKB1VeV43JNIQoCoo/ duDoZ1MldohJI5n0tC6sTkK3UMBZY6Lwk3kjTM0k8ms+vZMahmOQW7Q8poYXa11x A/kgx22ETwM3LUqnAj7VRk2k3KcBf5ZUxHpwtVwb9c5/QCDmtBDll99OxBzGd5Q= =iuCp -----END PGP SIGNATURE----- --9dIfJ6BqUNshnNWvw7SVGbh00P5PfGmUB-- From debbugs-submit-bounces@debbugs.gnu.org Sat Aug 08 07:00:26 2015 Received: (at submit) by debbugs.gnu.org; 8 Aug 2015 11:00:26 +0000 Received: from localhost ([127.0.0.1]:50646 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZO1rV-0006Tb-P4 for submit@debbugs.gnu.org; Sat, 08 Aug 2015 07:00:26 -0400 Received: from eggs.gnu.org ([208.118.235.92]:54724) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZO1rS-0006TS-Ld for submit@debbugs.gnu.org; Sat, 08 Aug 2015 07:00:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZO1rR-0004cL-4o for submit@debbugs.gnu.org; Sat, 08 Aug 2015 07:00:22 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:43902) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZO1rR-0004bu-1o for submit@debbugs.gnu.org; Sat, 08 Aug 2015 07:00:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39993) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZO1rQ-0002Wh-1K for bug-coreutils@gnu.org; Sat, 08 Aug 2015 07:00:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZO1rL-0004Vo-Vq for bug-coreutils@gnu.org; Sat, 08 Aug 2015 07:00:19 -0400 Received: from turms.7val.com ([213.196.234.34]:57065) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZO1rL-0004RL-Pj for bug-coreutils@gnu.org; Sat, 08 Aug 2015 07:00:15 -0400 Received: from localhost (amavis.7val.com [172.22.0.32]) by localhost (Postfix) with ESMTP id 0965F3955532 for ; Sat, 8 Aug 2015 13:00:11 +0200 (CEST) Received: from turms.7val.com ([172.22.0.34]) by localhost (amavis.7val.com [172.22.0.32]) (amavisd-new, port 10024) with ESMTP id QuFW3DV-k+ag for ; Sat, 8 Aug 2015 13:00:07 +0200 (CEST) Received: from qube.nonet (xdsl-87-79-119-63.netcologne.de [87.79.119.63]) by turms.7val.com (Postfix) with ESMTP for ; Sat, 8 Aug 2015 13:00:07 +0200 (CEST) Received: from tezro.nonet (tezro.nonet [10.0.0.1]) by qube.nonet (Postfix) with ESMTP id E14ED2DB07 for ; Sat, 8 Aug 2015 13:00:05 +0200 (CEST) Received: from tezro.nonet (localhost [127.0.0.1]) by tezro.nonet (SGI-8.12.11.20060308/8.12.11) with ESMTP id t78AxpEd002167 for ; Sat, 8 Aug 2015 12:59:51 +0200 (CEST) Received: (from canavan@localhost) by tezro.nonet (SGI-8.12.11.20060308/8.12.11/Submit) id t78Axoo7002165 for bug-coreutils@gnu.org; Sat, 8 Aug 2015 12:59:50 +0200 (CEST) Message-Id: <201508081059.t78Axoo7002165@tezro.nonet> Date: Sat, 8 Aug 2015 12:59:50 +0200 (CEST) To: bug-coreutils@gnu.org Subject: Re: bug#21218: ls -d From: "Rainer M. Canavan" In-Reply-To: <55C57AE2.1010803@redhat.com> X-Mailer: Ishmail 2.1.0-20150803-mips-sgi-irix6.5 MIME-Version: 1.0 Content-Type: text/plain X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x [fuzzy] X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) Eric Blake wrote: [...] > All -d does is to list command line arguments that are directories as > the name of the directory itself, rather than descending and showing the > directory's contents. That description is already better than the current one in the man page, which reads: -d, --directory list directory entries instead of contents, and do not derefer- ence symbolic links I'd say that one can reasonably be understood to mean that files would not be listed, as Eddie did. I'd suggest a new wording: -d, --directory If an argument is a directory, list the directory itself instead of its contents. Frequently used with -l to display the properties of directories. I don't see any relevant effect on symbolic links, so unless soeone can come up with an explanation, maybe that part can be dropped. $ ls -ld b lrwxr-xr-x 1 canavan user 1 Aug 8 12:45 b -> a $ ls -l b lrwxr-xr-x 1 canavan user 1 Aug 8 12:45 b -> a $ ls -d b b $ ls b b rainer From debbugs-submit-bounces@debbugs.gnu.org Sun Aug 09 14:47:46 2015 Received: (at 21218) by debbugs.gnu.org; 9 Aug 2015 18:47:46 +0000 Received: from localhost ([127.0.0.1]:51432 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZOVdJ-0004eW-Vc for submit@debbugs.gnu.org; Sun, 09 Aug 2015 14:47:46 -0400 Received: from joseki.proulx.com ([216.17.153.58]:58001) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZOVcz-0004dz-1I for 21218@debbugs.gnu.org; Sun, 09 Aug 2015 14:47:43 -0400 Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119]) by joseki.proulx.com (Postfix) with ESMTP id 2B48D2183C; Sun, 9 Aug 2015 12:47:24 -0600 (MDT) Received: by hysteria.proulx.com (Postfix, from userid 1000) id 055AA2DC52; Sun, 9 Aug 2015 12:47:23 -0600 (MDT) Date: Sun, 9 Aug 2015 12:47:23 -0600 From: Bob Proulx To: "Sneeh, Eddie" Subject: Re: bug#21218: ls -d Message-ID: <20150809124605199337982@bob.proulx.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 21218 Cc: 21218@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) Sneeh, Eddie wrote: > I believe there is a problem with ls -d (unless the intent is to just list > 1 directory). Just noting this has an FAQ entry: http://www.gnu.org/software/coreutils/faq/coreutils-faq.html#ls-_002dd-does-not-list-directories_0021 Bob From debbugs-submit-bounces@debbugs.gnu.org Mon Aug 10 15:28:27 2015 Received: (at 21218-done) by debbugs.gnu.org; 10 Aug 2015 19:28:27 +0000 Received: from localhost ([127.0.0.1]:52431 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZOskD-0007wk-S1 for submit@debbugs.gnu.org; Mon, 10 Aug 2015 15:28:26 -0400 Received: from mailgate3.roche.com ([196.3.50.142]:59614) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZOsSV-0007Wu-6y for 21218-done@debbugs.gnu.org; Mon, 10 Aug 2015 15:10:08 -0400 Received: from 145.245.200.230 (EHLO mg-int6.roche.com) ([145.245.200.230]) by mailgate3.roche.com (MOS 4.4.4-GA FastPath queued) with ESMTP id ABO99782; Mon, 10 Aug 2015 21:10:06 +0200 (CEST) Received: from 196.3.47.253 (EHLO mail-wi0-f175.google.com) ([196.3.47.253]) by mg-int6.roche.com (MOS 4.4.4-GA FastPath queued) with ESMTP id DUI94796; Mon, 10 Aug 2015 21:10:06 +0200 (CEST) Received: by mail-wi0-f175.google.com with SMTP id ja10so38151349wic.1 for <21218-done@debbugs.gnu.org>; Mon, 10 Aug 2015 12:10:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=9T9t7EWXNx+EMm60ihwtM2hYjJc8Fr6lcrhhkM6HQdk=; b=BMWfZDzH7bQFRuLPBVMBzsr2+7LNgCeN7ADzVcpPx/0Y048+cbGo64jdQAbFIVSA8A AsMA88xEgDQRelI4SdzV5RWgcIltCmEVbVPT7MoKM02KP3DQf/FpkQUyOfmVH3KdVTga i0LfHPXI9+93RPuyI53YaYeiObFcwMKN1C9wcy3X6FxbjxgjdyXKQ+QURsmrn6hKXsgh IjUEIEWjJVT2S39O1XTbq6kZdymMYBqB6ScbyetXXuJljT4HX+Yp4vmXtniBDYJTbprU +J0F9yNAUc/Ur/xgNvlyIfPZFR2k8vrgI9zkqP9gCFD0o1zbfQxne0dLHLBOk/Csapri 2P6g== X-Gm-Message-State: ALoCoQkKgREcjYe+1UeNIfkRikKznbfciVj30M/Oqg4GMQrIulvJPYZxYHzvaGmxP26QDYVG4CcfSn9yMzgcHecxlMzmcBLnvjZlhhzPg2KkpQvBqR7M6akz+3NusWaObFo+pkW41JgWmI+N6TzA9EtXo6Be9c35jQ== X-Received: by 10.180.210.200 with SMTP id mw8mr26554588wic.26.1439233800849; Mon, 10 Aug 2015 12:10:00 -0700 (PDT) X-Received: by 10.180.210.200 with SMTP id mw8mr26554537wic.26.1439233800441; Mon, 10 Aug 2015 12:10:00 -0700 (PDT) MIME-Version: 1.0 Received: by 10.27.214.72 with HTTP; Mon, 10 Aug 2015 12:09:21 -0700 (PDT) In-Reply-To: <55C57AE2.1010803@redhat.com> References: <55C57AE2.1010803@redhat.com> From: "Sneeh, Eddie" Date: Mon, 10 Aug 2015 12:09:21 -0700 Message-ID: Subject: Re: bug#21218: ls -d To: Eric Blake Content-Type: multipart/alternative; boundary=001a11c343346ca724051cf9bb46 X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 21218-done X-Mailman-Approved-At: Mon, 10 Aug 2015 15:28:24 -0400 Cc: 21218-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) --001a11c343346ca724051cf9bb46 Content-Type: text/plain; charset=UTF-8 Hi Eric, thanks for the quick response and clarification. I wasn't completely clear what -d was supposed to do exactly. The man pages define ls -d as: *"list directory entries instead of contents".* The files in the target directory are contents of that directory, but they get listed anyway! I still think ls -d is not accurate. Here are some examples: % \ls -d f1 f1 (but f1 is not a "directory entry" so this output is not consistent with the definition above.) If: % \ls /tmp/mydir d1/ d2/ f1 f2 % \ls -d . . (but where are the rest of the directories?) % \ls -d /tmp/mydir /tmp/mydir (Same thing, no listing of directory entries in that directory as the definition says) The behavior I'm seeing is: list directory entries instead of contents, *but not including the parent directory (or the directory specified as argument)*. I guess that's where the confusion is. IMHO, the directory that the user specifies should be the first to follow the rule, because that's what the user is concerned about the most. % \ls -d * can be accomplished by a simple: % \ls % \ls -d wrote: > tag 21218 notabug > thanks > > On 08/07/2015 06:01 PM, Sneeh, Eddie wrote: > > Hi, > > I believe there is a problem with ls -d (unless the intent is to just > list > > 1 directory). > > Thanks for the report. However, I think you have misunderstood the > purpose of -d. Try this for comparison: > > touch file > ls . file > ls -d . file > > All -d does is to list command line arguments that are directories as > the name of the directory itself, rather than descending and showing the > directory's contents. > > > Say I have a dir mydir, it has directories d1 and d2, and files f1 and > f2. > > I want to list only d1 and d2. How do I do that? I tried ls -d but that > > doesn't seem to work: > > \ls -d mydir > > returns: mydir > > \ls -d mydir/* > > returns: mydir/d1 mydir/d2 mydir/f1 mydir/f2 > > but f1 and f2 are files. > > If you want to list ONLY directories, use a glob that guarantees only > directories can be matched: > > ls -d mydir/*/ > > The trailing slash can only match directories, and will therefore skip > ordinary files. Or, you can use find: > > find mydir -mindepth 1 -maxdepth 2 -type d > > I'm closing this as not a bug as ls is working as designed, but feel > free to ask further questions. > > -- > Eric Blake eblake redhat com +1-919-301-3266 > Libvirt virtualization library http://libvirt.org > > -- Best Regards, *Eddie Sneeh* --001a11c343346ca724051cf9bb46 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi Eric, thanks for the quick response and clarification.=C2=A0 = I wasn't completely clear what -d was supposed to do exactly.=C2=A0 The= man pages define ls -d as:
"list directory entries instead of conte= nts".
The files in the target directory are contents of that direct= ory, but they get listed anyway! =C2=A0 I still think ls -d is not accurate= . =C2=A0 Here are some examples:
% \ls -d f1
f1
(but f1 is not a "directo= ry entry" so this output is not consistent with the definition above.)=
=
If:
% \ls /tmp/mydir
d1/ d2/ f1 f2
% \ls -d .
.
(but where are the rest of t= he directories?)
% \ls -d /tmp/mydir
/tmp/mydir
(Same thing, no listing of dir= ectory entries in that directory as the definition says)
The behavior I'= m seeing is: =C2=A0list directory entries instead of contents, but not i= ncluding the parent directory (or the directory specified as argument).= =C2=A0 I guess that's where the confusion is.=C2=A0 IMHO, the directory= that the user specifies should be the first to follow the rule, because th= at's what the user is concerned about the most.
% \ls -d *
can be accompl= ished by a simple:
% \ls
% \ls -d <directory I'm concerned about)
just = does a pwd!


Thanks for the find command.=C2=A0 That's what most = of us have been doing, but I feel that listing directories/files/links shou= ld be an ls function more so than a find's, and it should be a simple c= ommand rather than a long one.=C2=A0 If it were up to me, this is what I wo= uld do:
% ls -f =C2=A0(list files)
% ls -l (list links)=C2=A0
% ls -d (list = directories)
This is more intuitive and useful, at least to me.
The man pages= for ls -f say: "do not sort" =C2=A0I'm not sure how -f was d= erived from that.
Since these switches are already taken to do other things,= what do you think about this:
% ls -fo (list files only)
% ls -lo (list link= s only)
% ls -do (list directories only)

For now, I like your solution: l= s -d */ =C2=A0 which I'll be using instead of the find command.=C2=A0 I= 'll have to "tolerate" the extra slash at the end, but I like= this better than other options. =C2=A0 Thanks again.

Eddie=C2=A0

<= /div>
<= br>




On Fri, Aug 7, 2015 at 8:43 PM, Eric Blake <eblake@redhat.com><= /span> wrote:
tag 21218 notabug
thanks

On 08/07/2015 06:01 PM, Sneeh, Eddie wrote:
> Hi,
> I believe there is a problem with ls -d (unless the intent is to just = list
> 1 directory).

Thanks for the report.=C2=A0 However, I think you have misunderstood the purpose of -d.=C2=A0 Try this for comparison:

touch file
ls . file
ls -d . file

All -d does is to list command line arguments that are directories as
the name of the directory itself, rather than descending and showing the directory's contents.

> Say I have a dir mydir, it has directories d1 and d2, and files f1 and= f2.
> I want to list only d1 and d2.=C2=A0 How do I do that?=C2=A0 I tried l= s -d but that
> doesn't seem to work:
> \ls -d mydir
> returns: mydir
> \ls -d mydir/*
> returns: mydir/d1 mydir/d2 mydir/f1 mydir/f2
> but f1 and f2 are files.

If you want to list ONLY directories, use a glob that guarantees only
directories can be matched:

ls -d mydir/*/

The trailing slash can only match directories, and will therefore skip
ordinary files.=C2=A0 Or, you can use find:

find mydir -mindepth 1 -maxdepth 2 -type d

I'm closing this as not a bug as ls is working as designed, but feel free to ask further questions.

--
Eric Blake=C2=A0 =C2=A0eblake redhat com=C2=A0 =C2=A0 +1-919-301-3266
Libvirt virtualization library http://libvirt.org




--
Best Regards,
Eddie Sneeh
--001a11c343346ca724051cf9bb46-- From debbugs-submit-bounces@debbugs.gnu.org Mon Aug 10 15:41:16 2015 Received: (at 21218) by debbugs.gnu.org; 10 Aug 2015 19:41:16 +0000 Received: from localhost ([127.0.0.1]:52438 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZOswe-0008Hd-3K for submit@debbugs.gnu.org; Mon, 10 Aug 2015 15:41:16 -0400 Received: from mailgate3.roche.com ([196.3.50.142]:33406) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZOswb-0008HU-OI for 21218@debbugs.gnu.org; Mon, 10 Aug 2015 15:41:14 -0400 Received: from 145.245.200.230 (EHLO mg-int6.roche.com) ([145.245.200.230]) by mailgate3.roche.com (MOS 4.4.4-GA FastPath queued) with ESMTP id ABP18839; Mon, 10 Aug 2015 21:41:13 +0200 (CEST) Received: from 196.3.47.253 (EHLO mail-wi0-f179.google.com) ([196.3.47.253]) by mg-int6.roche.com (MOS 4.4.4-GA FastPath queued) with ESMTP id DUJ03846; Mon, 10 Aug 2015 21:41:12 +0200 (CEST) Received: by mail-wi0-f179.google.com with SMTP id ja10so38771912wic.1 for <21218@debbugs.gnu.org>; Mon, 10 Aug 2015 12:41:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=9sY26RC7wle6ZtE/Xsb50/8WYmROZax5Y+CSkMfEPnk=; b=mRSengUP05E8DrBtky6Eu6CtJJortjglTuqIzfYiH+SOuzrGsnMry1JW9ZAg4zndlf OWQgyG8TNRtKJRC3zPJ/x5jMoPpmhhb6iujoyF3nuTXeqyq+vKMMMZZcRTEcBiFb+wkF pwIBcENrszxz2EsOVrW5XN6QbYSPxM6yHyKN+4MFuCvZ1/rNlxe2Fols2HYGwoMBFgrU Tq385mKjSu7nTwbaMbp6TEB5zzYcQaWTLY1t85VlDnY7AeAMQjkw7hxF5VIFKBR+bY69 WKlNHZF6QVWS49lmcah8sj43dn/I3Y9GvFGKN1Ij/aCHz5Fz8+X8bvJQMUBiXfCLOuVo VENA== X-Gm-Message-State: ALoCoQmP9f/jsLDkagAiklOHxAJjYlTspqkopuZloA88LgVoSE19Xi+6/GczxjyRMfK1IvtGk1sakUbdoRtMJQI50pYbH+nniUNIIpQzqPed0BplSFbBOOTuk2nL6/KJ7ujGx0KAoHC4 X-Received: by 10.194.191.164 with SMTP id gz4mr47241957wjc.21.1439235662360; Mon, 10 Aug 2015 12:41:02 -0700 (PDT) X-Received: by 10.194.191.164 with SMTP id gz4mr47241889wjc.21.1439235661951; Mon, 10 Aug 2015 12:41:01 -0700 (PDT) MIME-Version: 1.0 Received: by 10.27.214.72 with HTTP; Mon, 10 Aug 2015 12:40:22 -0700 (PDT) In-Reply-To: <20150809124605199337982@bob.proulx.com> References: <20150809124605199337982@bob.proulx.com> From: "Sneeh, Eddie" Date: Mon, 10 Aug 2015 12:40:22 -0700 Message-ID: Subject: Re: bug#21218: ls -d To: Bob Proulx Content-Type: multipart/alternative; boundary=047d7ba98212611a04051cfa2ae3 X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 21218 Cc: 21218@debbugs.gnu.org, Eric Blake X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) --047d7ba98212611a04051cfa2ae3 Content-Type: text/plain; charset=UTF-8 Hi Bob, thanks for the info. If ya'll don't want to consider this a bug, that's fine, but I suggest updating the definition for -d to clarify the true behavior. If it must be used with other options for it to be useful, then the definition should say so because I sure don't see "list directory entries instead of contents". I'm yet to see the usefulness of this option (used alone), other than in Eric's example, which is what I was after. If someone has some examples of ls -d usage, *without adding other switches* , I'd appreciate it. Thanks again, Eddie On Sun, Aug 9, 2015 at 11:47 AM, Bob Proulx wrote: > Sneeh, Eddie wrote: > > I believe there is a problem with ls -d (unless the intent is to just > list > > 1 directory). > > Just noting this has an FAQ entry: > > > http://www.gnu.org/software/coreutils/faq/coreutils-faq.html#ls-_002dd-does-not-list-directories_0021 > > Bob > -- Best Regards, *Eddie Sneeh* --047d7ba98212611a04051cfa2ae3 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi Bob, thanks for the info.
If ya'll don't want to consi= der this a bug, that's fine, but I suggest updating the definition for = -d to clarify the true behavior.=C2=A0 If it must be used with other option= s for it to be useful, then the definition should say so because I sure don= 't see "list directory entries instead of contents".
I'm y= et to see the usefulness of this option (used alone), other than in Eric= 9;s example, which is what I was after.
If someone has some examples of = ls -d usage,=C2=A0without adding other switches=C2=A0, I'd appre= ciate it.
Thanks again,
Eddie


<= div class=3D"gmail_quote">On Sun, Aug 9, 2015 at 11:47 AM, Bob Proulx <bob@pr= oulx.com> wrote:
Sneeh, E= ddie wrote:
> I believe there is a problem with ls -d (unless the intent is to just = list
> 1 directory).

Just noting this has an FAQ entry:

=C2=A0 http://www.gnu.org/software/coreutils/faq/coreutils-faq.html#ls-_00= 2dd-does-not-list-directories_0021

Bob



--
Best Regards,
Eddie Sneeh
--047d7ba98212611a04051cfa2ae3-- From debbugs-submit-bounces@debbugs.gnu.org Mon Aug 10 16:37:19 2015 Received: (at 21218-done) by debbugs.gnu.org; 10 Aug 2015 20:37:19 +0000 Received: from localhost ([127.0.0.1]:52465 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZOtot-00017Z-1t for submit@debbugs.gnu.org; Mon, 10 Aug 2015 16:37:19 -0400 Received: from mail-qg0-f41.google.com ([209.85.192.41]:33973) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZOtoq-00017R-OQ for 21218-done@debbugs.gnu.org; Mon, 10 Aug 2015 16:37:17 -0400 Received: by qgeg42 with SMTP id g42so89721859qge.1 for <21218-done@debbugs.gnu.org>; Mon, 10 Aug 2015 13:37:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=2R1kr72eypkEUMepboCbhTPZP0sSMnGVwARPHj42OwQ=; b=K10tl605stuAUM+Ef3n01zaaFgGHtTZEBQSwo4iL0aYgwOEPzEQ3kb6yLWc/GUcPBr z9KO2MYa+JcUlE9PwRPQ11FKVW7mdV4At2TVmDYDaP6QxV4kt42q9kGZMTHzJk5ce3/G OzSL+NpJqPNcaT88NP37hqC0bv69Wt5WcA7fYEi3DvGG22fcbrx0AaBX006H3FzB1jA7 e2I/KIVYXI+7fWlAFMbdBPCxHa8/aqi1+YRZ/YHiprrW4rUrzxqeZjD3i/fRnLy9sVbC /lXdHTeAyFOM5grQ4NKOJ5bTQeuAtbiaqAeiAyJhQ8y9XY0ZVHn0HfHR9faw5lKnvyO6 XNjg== X-Received: by 10.140.25.132 with SMTP id 4mr4729447qgt.104.1439239036224; Mon, 10 Aug 2015 13:37:16 -0700 (PDT) Received: from gmail.com (housegordon.org. [104.236.108.240]) by smtp.gmail.com with ESMTPSA id g30sm10507312qge.11.2015.08.10.13.37.14 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 10 Aug 2015 13:37:15 -0700 (PDT) Date: Mon, 10 Aug 2015 20:36:44 +0000 From: Assaf Gordon To: "Sneeh, Eddie" Subject: Re: bug#21218: ls -d Message-ID: <20150810203643.GB24162@gmail.com> References: <55C57AE2.1010803@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Score: 0.3 (/) X-Debbugs-Envelope-To: 21218-done Cc: Eric Blake , 21218-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.3 (/) Hello Eddie, (replying to your two last messages together) On Mon, Aug 10, 2015 at 12:09:21PM -0700, Sneeh, Eddie wrote: >Hi Eric, thanks for the quick response and clarification. I wasn't >completely clear what -d was supposed to do exactly. The man pages define >ls -d as: >*"list directory entries instead of contents".* The wording above is perhaps not clear, and indeed, recent versions of GNU coreutils it have been re-worded to: -d --directory List just the names of directories, as with other types of files, rather than listing their contents. (in http://www.gnu.org/software/coreutils/manual/html_node/Which-files-are-listed.html#Which-files-are-listed) And: -d, --directory list directories themselves, not their contents (from 'ls --help' or 'man ls') POSIX explains it as so: -d [...] Do not treat directories differently than other types of files. (in http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html) And OpenBSD explains it as: -d Directories are listed as plain files (from 'man ls' on OpenBSD - this is not GNU Coreutils' ls) The term "directory entries" refers to the technical item of a "file system entry", which represent the information about the directory itself (e.g. when was it created and who is the owner). This term was indeed confusing, and so it was changed in 2013 in this commit: http://git.savannah.gnu.org/cgit/coreutils.git/commit/?id=da398ae5dfa43efda48310899c24242da4764f44 To give a concrete example: # This means: list information about files INSIDE directory f1 ls -l f1 # This means: list information about directory f1 itself # (such as who is the owner, access permissions, # and when was it created) ls -ld f1 (replying to your second message): On 08/10/2015 03:40 PM, Sneeh, Eddie wrote: > Hi Bob, thanks for the info. > If ya'll don't want to consider this a bug, that's fine, but I suggest > updating the definition for -d to clarify the true behavior. The wording has been already updated, so that's fixed. > I'm yet to see the usefulness of this option (used alone), other than > in Eric's example, which is what I was after. > If someone has some examples of ls -d usage, _without adding other > switches_ , I'd appreciate it. I can give a contrived example, but hopefully it will demonstrate that there are some uses cases. Imagine the following content of a directory: touch a1 a2 a3 b1 b2 b3 mkdir b4 touch b4/foo To list everything, typing 'ls' would suffice: $ ls 1 2 3 4 6 a1 a2 a3 b1 b2 b3 b4 Now, I want to see only 'things' starting with 'b'. Note that by 'things' I mean both files and directories. From a purely technical POV, on many file-systems a 'directory' is just a file, but with a different file-system type, so sometimes technical purists will say 'files' and also mean directories (and similarly, special devices, named fifos, sockets - they are all 'files'). back to listing things starting with 'b': $ ls b* b1 b2 b3 b4: foo The above might be unexpected output. Because 'b4' is a directory, ls entered it and listed its content (foo). If I want to see only list of things (=files,directories,everything), that's where '-d' comes in handy: $ ls -d b* b1 b2 b3 b4 > For now, I like your solution: ls -d */ which I'll be using instead > of the find command. If you use 'ls */' to view directories interactively, that's fine. If you use it for any kind of scripting (e.g. in a shell for/while loop or xargs), then it is highly recommended to use 'find' instead of 'ls' - a file containing any kind of funky characters (spaces, tabs, newlines, etc.) might confuse your script and cause unintended conseqeunces. To save some typing, you can create the following shell function (e.g. in your '~/.bashrc' file): lsd(){ find ${1:-.} -mindepth 1 -maxdepth 1 -type d -printf "%f\n";} And then run 'lsd' or 'lsd DIR' to list the current or the specified directory. In scripting, it is recommended to use '-print0' to prevent issues with files that might contain whitespaces, e.g.: find DIR -mindepth 1 -maxdepth 1 -type d -print0 \ | xargs -0 -I% echo "Processing directory %" Regards, - assaf From debbugs-submit-bounces@debbugs.gnu.org Mon Aug 10 16:47:39 2015 Received: (at 21218-done) by debbugs.gnu.org; 10 Aug 2015 20:47:39 +0000 Received: from localhost ([127.0.0.1]:52489 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZOtys-0001Mp-Ox for submit@debbugs.gnu.org; Mon, 10 Aug 2015 16:47:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53123) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZOtyq-0001Mf-8v for 21218-done@debbugs.gnu.org; Mon, 10 Aug 2015 16:47:37 -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 (Postfix) with ESMTPS id 26452A303C; Mon, 10 Aug 2015 20:47:35 +0000 (UTC) Received: from [10.3.113.21] (ovpn-113-21.phx2.redhat.com [10.3.113.21]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t7AKlYb3031602; Mon, 10 Aug 2015 16:47:34 -0400 Subject: Re: bug#21218: ls -d To: "Sneeh, Eddie" References: <55C57AE2.1010803@redhat.com> From: Eric Blake Openpgp: url=http://people.redhat.com/eblake/eblake.gpg Organization: Red Hat, Inc. Message-ID: <55C90DE1.8020609@redhat.com> Date: Mon, 10 Aug 2015 14:47:29 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="CjPvqwJFBPAd2B9TX5nq7HCLvp7Rj9Cqm" X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: 21218-done Cc: 21218-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --CjPvqwJFBPAd2B9TX5nq7HCLvp7Rj9Cqm Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 08/10/2015 01:09 PM, Sneeh, Eddie wrote: > Since these switches are already taken to do other things, what do you > think about this: > % ls -fo (list files only) > % ls -lo (list links only) > % ls -do (list directories only) Won't work. 'ls -o' is already a valid command, so 'ls -fo' is the same as 'ls -o -f' or 'ls -f -o'. You can't start a long-option name with a single dash; at least, not in coreutils which uses getopt_long() (there are some exceptions, like gcc, which use getopt_long_only() for historical reasons, and which therefore can spell long options with a single dash if there is no ambiguity, but use of getopt_long_only() is not recommended in new programs). --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --CjPvqwJFBPAd2B9TX5nq7HCLvp7Rj9Cqm Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJVyQ3hAAoJEKeha0olJ0NqWLQH/0mDZaRM8tVNY6rIZlygqGQE LwnLRGZU5WtQdPTmmfergTcA0uBDkpgnwKqxRetjv1MsSDg7lrwZpHGQ8m/rda9e Pqf1KsQ51FehZ5vUNQUFFgPjYyF6Qdfb+Ugm0j6wmeALlpLN8+nO/QiIStn8RlZ5 Xegt35hmbgNg4+uVyxgqBOmlx19imVWZy/SoMiqJhRVCXKNA7kHVrFn3Jbh5UvxP Gvt34x6U9NbGYQ+a3ZUuOZRyT+ft5h+iPLMf6mxk9RYamPLj4D1wZ3mxmGI+Q0Hy veTdFtlas33pIWHAhi9AJY9oohViOvWN3h2ce8LU7DCDNXR/FOOCFWHoNhG+fpc= =xY29 -----END PGP SIGNATURE----- --CjPvqwJFBPAd2B9TX5nq7HCLvp7Rj9Cqm-- From debbugs-submit-bounces@debbugs.gnu.org Mon Aug 10 17:08:29 2015 Received: (at 21218-done) by debbugs.gnu.org; 10 Aug 2015 21:08:29 +0000 Received: from localhost ([127.0.0.1]:52498 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZOuJ3-0001pv-6J for submit@debbugs.gnu.org; Mon, 10 Aug 2015 17:08:29 -0400 Received: from mailgate3.roche.com ([196.3.50.142]:1738) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZOuJ0-0001pl-W0 for 21218-done@debbugs.gnu.org; Mon, 10 Aug 2015 17:08:27 -0400 Received: from 145.245.200.231 (EHLO mg-int2.roche.com) ([145.245.200.231]) by mailgate3.roche.com (MOS 4.4.4-GA FastPath queued) with ESMTP id ABP65079; Mon, 10 Aug 2015 23:08:26 +0200 (CEST) Received: from 196.3.47.253 (EHLO mail-wi0-f174.google.com) ([196.3.47.253]) by mg-int2.roche.com (MOS 4.4.4-GA FastPath queued) with ESMTP id DGW37550; Mon, 10 Aug 2015 23:08:25 +0200 (CEST) Received: by mail-wi0-f174.google.com with SMTP id ne3so37144490wic.0 for <21218-done@debbugs.gnu.org>; Mon, 10 Aug 2015 14:08:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=L5VE7PVLjiJMYxsCWeZpiVUxYXBYEz+5adL/nCAp5FU=; b=H3iEBIIo5ENFu7zzsG096SqVX8tBm31k+pHfB33JkgBiL9VfnVe9rdPS7XcIqQL3yI JpQe9aOht7PxuW2UC/Nyl+sZfckxXEF/t5WbD5zupLkOEJRE0Cazk5sZxWJWdoqwOwzC OWxsjK+1tOKrP2bgU6LHZiZbsOd04uZxuc2foWNjleSEWkB9WkBa12BxjOPUsdS6i0yh AT8nEvJTROA5GemlQRiSmqdPR5E3F1/areYH26AAWnniV/0jS+nC0pASzN535ckGr+lh mxI9j4LPj6eKpIKZ+2w06d4ApKOgNWdGFr2g2Fjya4bfq5JCZ7Mm7pTnKdwkeKwcdN0N Hq9g== X-Gm-Message-State: ALoCoQmX+psMvbZzkfPrbO/Y8pQzQ0LjRukdMyIxdFB+dIyMtVj25fVbdU5S2IatWU0eCaiMNr6ub0529LHe8gQHXmr7Yb5wv1bZ843VEP+rbwIwobFczP1VvsAM5nHrzDJBbg0uZD8O7DX1sa+4MaxBh3mQF0jynA== X-Received: by 10.194.191.164 with SMTP id gz4mr47994631wjc.21.1439240905711; Mon, 10 Aug 2015 14:08:25 -0700 (PDT) X-Received: by 10.194.191.164 with SMTP id gz4mr47994573wjc.21.1439240905301; Mon, 10 Aug 2015 14:08:25 -0700 (PDT) MIME-Version: 1.0 Received: by 10.27.178.105 with HTTP; Mon, 10 Aug 2015 14:07:45 -0700 (PDT) In-Reply-To: <55C90DE1.8020609@redhat.com> References: <55C57AE2.1010803@redhat.com> <55C90DE1.8020609@redhat.com> From: "Sneeh, Eddie" Date: Mon, 10 Aug 2015 14:07:45 -0700 Message-ID: Subject: Re: bug#21218: ls -d To: Eric Blake Content-Type: multipart/alternative; boundary=047d7ba98212e83dac051cfb626c X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 21218-done Cc: 21218-done <21218-done@debbugs.gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) --047d7ba98212e83dac051cfb626c Content-Type: text/plain; charset=UTF-8 Ah yes -do is the same as -d -o, overlooked that. Looks like most the alphabet is already taken, o is taken, n is taken, l is taken, is y still available? (Am I seeing this right, only -e and -y are still unused?) On Mon, Aug 10, 2015 at 1:47 PM, Eric Blake wrote: > On 08/10/2015 01:09 PM, Sneeh, Eddie wrote: > > > Since these switches are already taken to do other things, what do you > > think about this: > > % ls -fo (list files only) > > % ls -lo (list links only) > > % ls -do (list directories only) > > Won't work. 'ls -o' is already a valid command, so 'ls -fo' is the same > as 'ls -o -f' or 'ls -f -o'. You can't start a long-option name with a > single dash; at least, not in coreutils which uses getopt_long() (there > are some exceptions, like gcc, which use getopt_long_only() for > historical reasons, and which therefore can spell long options with a > single dash if there is no ambiguity, but use of getopt_long_only() is > not recommended in new programs). > > -- > Eric Blake eblake redhat com +1-919-301-3266 > Libvirt virtualization library http://libvirt.org > > -- Best Regards, *Eddie Sneeh* --047d7ba98212e83dac051cfb626c Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Ah yes -do is the same as -d -o, overlooked that.=C2=A0 Looks li= ke most the alphabet is already taken, o is taken, n is taken, l is taken, = is y still available? (Am I seeing this right, only -e and -y are still unu= sed?)


On Mon, Aug 10, 2015 at 1:47 PM, Eric Blake <eblake@redhat.com>= wrote:
On 08/10/2015 01:09 PM, Sn= eeh, Eddie wrote:

> Since these switches are already taken to do other things, what do you=
> think about this:
> % ls -fo (list files only)
> % ls -lo (list links only)
> % ls -do (list directories only)

Won't work.=C2=A0 'ls -o' is already a valid command, so 'l= s -fo' is the same
as 'ls -o -f' or 'ls -f -o'.=C2=A0 You can't start a lo= ng-option name with a
single dash; at least, not in coreutils which uses getopt_long() (there
are some exceptions, like gcc, which use getopt_long_only() for
historical reasons, and which therefore can spell long options with a
single dash if there is no ambiguity, but use of getopt_long_only() is
not recommended in new programs).

--
Eric Blake=C2=A0 =C2=A0eblake redhat com=C2=A0 =C2=A0 +1-919-301-3266
Libvirt virtualization library http://libvirt.org




--
Best Regards,
Eddie Sneeh
--047d7ba98212e83dac051cfb626c-- From debbugs-submit-bounces@debbugs.gnu.org Mon Aug 10 19:24:56 2015 Received: (at 21218-done) by debbugs.gnu.org; 10 Aug 2015 23:24:56 +0000 Received: from localhost ([127.0.0.1]:52576 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZOwR5-0005Bt-4h for submit@debbugs.gnu.org; Mon, 10 Aug 2015 19:24:56 -0400 Received: from mailgate1.roche.com ([196.3.50.140]:23898) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZOwR1-0005Bi-FW for 21218-done@debbugs.gnu.org; Mon, 10 Aug 2015 19:24:53 -0400 Received: from 145.245.200.230 (EHLO mg-int1.roche.com) ([145.245.200.230]) by mailgate1.roche.com (MOS 4.4.4-GA FastPath queued) with ESMTP id AGQ33071; Tue, 11 Aug 2015 01:24:50 +0200 (CEST) Received: from 196.3.47.253 (EHLO mail-wi0-f182.google.com) ([196.3.47.253]) by mg-int1.roche.com (MOS 4.4.4-GA FastPath queued) with ESMTP id DIW37673; Tue, 11 Aug 2015 01:24:50 +0200 (CEST) Received: by mail-wi0-f182.google.com with SMTP id p15so154407499wij.0 for <21218-done@debbugs.gnu.org>; Mon, 10 Aug 2015 16:24:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=hnM9T8S6zS2IrCsu/RhQ87j5zEtlUE8JNcvFzonezL4=; b=Cn3mVxwVfiTYLi0lPPQhQLKBWv7twnggwwCjg79GNgmI89GQkvZ+OSEY9xsRXALboZ fBpDWc8dloOn2ZUcinD6I+9l7boOXsn++fZz+82ZsnDcmDIqSWg/+tJ2wuE+TqKg8ubx 9fCof8N32YNhjJUo7/5ibavd02Ky9Iohh8HuFw4ldg0bvbNoFEI86T6mevKkLjXph8Jy XyaJimnEv+79m1AMlNjfDLDlvaDQeeD743uwSen5JP03M6QIFsNumGQ9Z2F36Dgf36wg CMLwU5n5PdiHEr6Pu92TTJVt1IkCIQQ2WtLuVYdi3QF9lnIb+uieaSIM7JxrHStd+i7N Yzdw== X-Gm-Message-State: ALoCoQkvDUD5G+5a5fAMrsQVf8/YNL3BqWkAM9z/F+O9+QgZinvFRCMF9DhAozZlidYWQWCnvmbSgnjolY4GbzbX9fpQrHOd8hqhiIZlRtdfqH1WFHG+vPUrf6TZsS+PSg3hA1yjL6hQoSpMmk/+a/9hcBKrFikWAA== X-Received: by 10.180.210.200 with SMTP id mw8mr28607441wic.26.1439249089977; Mon, 10 Aug 2015 16:24:49 -0700 (PDT) X-Received: by 10.180.210.200 with SMTP id mw8mr28607391wic.26.1439249089552; Mon, 10 Aug 2015 16:24:49 -0700 (PDT) MIME-Version: 1.0 Received: by 10.27.178.105 with HTTP; Mon, 10 Aug 2015 16:24:10 -0700 (PDT) In-Reply-To: <20150810203643.GB24162@gmail.com> References: <55C57AE2.1010803@redhat.com> <20150810203643.GB24162@gmail.com> From: "Sneeh, Eddie" Date: Mon, 10 Aug 2015 16:24:10 -0700 Message-ID: Subject: Re: bug#21218: ls -d To: Assaf Gordon Content-Type: multipart/alternative; boundary=001a11c34334ba0212051cfd4a35 X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 21218-done Cc: Eric Blake , 21218-done <21218-done@debbugs.gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) --001a11c34334ba0212051cfd4a35 Content-Type: text/plain; charset=UTF-8 Hi Assaf, I appreciate the thought and effort that went into constructing your reply. If you agree that the man pages are intended for all users, not just sys admins, then the definition of a directory would be a container of other things (files, links, directories). It does not mean a regular file. (Let's take devices/sockts/etc... out of the discussion. The majority of people don't deal with them.) Based on this definition of "directory", and keeping things simple and logical, if I wanted a listing of directories/files/links, what makes sense to me is ls (the definition being *list directory contents*). If I wanted to look for specific patterns, then find may be a better choice. Your example: ls -d b* does list directories at the current level (and it doesn't descend into subdirectories -- that's good), but it also lists *files* and *links* starting with the letter b! Try \ls -d d* f* l* It's going to list directories, and files and links. (in my example, d: directory, f: file, l: slink) I guess what it boils down to is "-d" is a confusing choice of option for what it really does. "ls --directory" has little to do with directories, (and adding the word "themselves" to the definition doesn't really remove much ambiguity), -d lists everything at one level, non-directories included! Again, imho, what I suggested is more intuitive: ls -d (list directories) ls -f (list files) ls -l (list links) The current -d should have been something like: --1level or --dont_descend or the like. I understand it's very difficult and late for any changes to happen. Thanks for listening! Your detailed response was, again, very much appreciated! Eddie On Mon, Aug 10, 2015 at 1:36 PM, Assaf Gordon wrote: > Hello Eddie, > > (replying to your two last messages together) > > On Mon, Aug 10, 2015 at 12:09:21PM -0700, Sneeh, Eddie wrote: > >> Hi Eric, thanks for the quick response and clarification. I wasn't >> completely clear what -d was supposed to do exactly. The man pages define >> ls -d as: >> *"list directory entries instead of contents".* >> > > The wording above is perhaps not clear, and indeed, recent versions of GNU > coreutils it have been re-worded to: > > -d > --directory > List just the names of directories, as with other > types of files, rather than listing their contents. > (in > http://www.gnu.org/software/coreutils/manual/html_node/Which-files-are-listed.html#Which-files-are-listed > ) > > And: > -d, --directory list directories themselves, not their contents > (from 'ls --help' or 'man ls') > > POSIX explains it as so: > > -d > [...] Do not treat directories differently than other types of files. > (in http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html) > > And OpenBSD explains it as: > > -d Directories are listed as plain files > (from 'man ls' on OpenBSD - this is not GNU Coreutils' ls) > > The term "directory entries" refers to the technical item of a "file > system entry", which represent the information about the directory itself > (e.g. when was it created and who is the owner). This term was indeed > confusing, and so it was changed in 2013 in this commit: > > http://git.savannah.gnu.org/cgit/coreutils.git/commit/?id=da398ae5dfa43efda48310899c24242da4764f44 > > To give a concrete example: > > # This means: list information about files INSIDE directory f1 > ls -l f1 > > # This means: list information about directory f1 itself > # (such as who is the owner, access permissions, > # and when was it created) > ls -ld f1 > > (replying to your second message): > > On 08/10/2015 03:40 PM, Sneeh, Eddie wrote: > >> Hi Bob, thanks for the info. >> If ya'll don't want to consider this a bug, that's fine, but I suggest >> updating the definition for -d to clarify the true behavior. >> > > The wording has been already updated, so that's fixed. > > I'm yet to see the usefulness of this option (used alone), other than in >> Eric's example, which is what I was after. >> If someone has some examples of ls -d usage, _without adding other >> switches_ , I'd appreciate it. >> > > I can give a contrived example, but hopefully it will demonstrate that > there are some uses cases. > > Imagine the following content of a directory: > > touch a1 a2 a3 b1 b2 b3 > mkdir b4 > touch b4/foo > > To list everything, typing 'ls' would suffice: > > $ ls > 1 2 3 4 6 a1 a2 a3 b1 b2 b3 b4 > > Now, I want to see only 'things' starting with 'b'. > Note that by 'things' I mean both files and directories. > From a purely technical POV, on many file-systems > a 'directory' is just a file, but with a different file-system type, > so sometimes technical purists will say 'files' and also mean directories > (and similarly, special devices, named fifos, sockets - they are all > 'files'). > back to listing things starting with 'b': > > $ ls b* > b1 b2 b3 > > b4: > foo > > The above might be unexpected output. Because 'b4' is a directory, ls > entered it and listed its content (foo). > If I want to see only list of things (=files,directories,everything), > that's where '-d' comes in handy: > > $ ls -d b* > b1 b2 b3 b4 > > For now, I like your solution: ls -d */ which I'll be using instead of >> the find command. >> > > If you use 'ls */' to view directories interactively, that's fine. > > If you use it for any kind of scripting (e.g. in a shell for/while loop or > xargs), then it is highly recommended to use 'find' instead of 'ls' - a > file containing any kind of funky characters (spaces, tabs, newlines, etc.) > might confuse your script and cause unintended conseqeunces. > > To save some typing, you can create the following shell function > (e.g. in your '~/.bashrc' file): > > lsd(){ find ${1:-.} -mindepth 1 -maxdepth 1 -type d -printf "%f\n";} > > And then run 'lsd' or 'lsd DIR' to list the current or the specified > directory. > > In scripting, it is recommended to use '-print0' to prevent issues > with files that might contain whitespaces, e.g.: > > find DIR -mindepth 1 -maxdepth 1 -type d -print0 \ > | xargs -0 -I% echo "Processing directory %" > > > Regards, > - assaf > -- Best Regards, *Eddie Sneeh* --001a11c34334ba0212051cfd4a35 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi Assaf, I appreciate the thought and effort that went into con= structing your reply.

If you agree that the man pages are intended for a= ll users, not just sys admins, then the definition of a directory would be = a container of other things (files, links, directories). =C2=A0 It does not= mean a regular file. =C2=A0(Let's take devices/sockts/etc... out of th= e discussion.=C2=A0 The majority of people don't deal with them.)
=

Ba= sed on this definition of "directory", and keeping things simple = and logical, if I wanted a listing of directories/files/links, what makes s= ense to me is ls (the definition being list directory contents).=C2= =A0 If I wanted to look for specific patterns, then find may be a better ch= oice.=C2=A0 Your example: ls -d b* does list directories at the current lev= el (and it doesn't descend into subdirectories -- that's good), but= it also lists files=C2=A0and links starting with the letter = b!
Try \ls -d d* f* l*
It's going to list directories, and files and link= s. =C2=A0(in my example, d: directory, f: file, l: slink)

I guess what= it boils down to is "-d" is a confusing choice of option for wha= t it really does. =C2=A0"ls --directory" has little to do with di= rectories, (and adding the word "themselves" to the definition do= esn't really remove much ambiguity), -d lists everything at one level, = non-directories included!

Again, imho, what I suggested is more intuitiv= e:
ls -d (list directories)
ls -f (list files)
ls -l (list links)
The current -= d should have been something like: --1level or --dont_descend or the like.<= /div>
I= understand it's very difficult and late for any changes to happen.=C2= =A0 Thanks for listening!=C2=A0 Your detailed response was, again, very muc= h appreciated!

Eddie




On Mon, Aug 10, 2015 at 1:36 PM, Assaf Gordon <= span dir=3D"ltr"><assafgordon@gmail.com> wrote:
Hello Eddie,

(replying to your two last messages together)

On Mon, Aug 10, 2015 at 12:09:21PM -0700, Sneeh, Eddie wrote:
Hi Eric, thanks for the quick response and clarification.=C2=A0 I wasn'= t
completely clear what -d was supposed to do exactly.=C2=A0 The man pages de= fine
ls -d as:
*"list directory entries instead of contents".*

The wording above is perhaps not clear, and indeed, recent versions of GNU = coreutils it have been re-worded to:

=C2=A0 =C2=A0 -d
=C2=A0 =C2=A0 --directory
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0List just the names of directories, as wi= th other
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0types of files, rather than listing their= contents.
=C2=A0 =C2=A0 (in http://www.gnu.org/software/coreutils/manual/html_no= de/Which-files-are-listed.html#Which-files-are-listed)

And:
=C2=A0 =C2=A0 -d, --directory=C2=A0 =C2=A0 =C2=A0 list directories themselv= es, not their contents
=C2=A0 =C2=A0 =C2=A0(from '= ls --help' or 'man ls')

POSIX explains it as so:

=C2=A0 =C2=A0 -d
=C2=A0 =C2=A0 [...] Do not treat directories differently than other types o= f files.
=C2=A0 =C2=A0 (in http://pubs.openg= roup.org/onlinepubs/9699919799/utilities/ls.html)

And OpenBSD explains it as:

=C2=A0 =C2=A0 -d=C2=A0 =C2=A0 =C2=A0 Directories are listed as plain files<= br> =C2=A0 =C2=A0 (from 'man ls' on OpenBSD - this is not GNU Coreutils= ' ls)

The term "directory entries" refers to the technical item of a &q= uot;file system entry", which represent the information about the dire= ctory itself (e.g. when was it created and who is the owner). This term was= indeed confusing, and so it was changed in 2013 in this commit:
= http://git.savannah.gnu.org/cgit/coreutils.git/commit/?id=3Dda398ae5dfa43ef= da48310899c24242da4764f44

To give a concrete example:

=C2=A0 =C2=A0 # This means: list information about files INSIDE directory f= 1
=C2=A0 =C2=A0 ls -l f1

=C2=A0 =C2=A0 # This means: list information about directory f1 itself
=C2=A0 =C2=A0 # (such as who is the owner, access permissions,
=C2=A0 =C2=A0 # and when was it created)
=C2=A0 =C2=A0 ls -ld f1

(replying to your second message):

On 08/10/2015 03:40 PM, Sneeh, Eddie wrote:
Hi Bob, thanks for the info.
If ya'll don't want to consider this a bug, that's fine, but I = suggest updating the definition for -d to clarify the true behavior.

The wording has been already updated, so that's fixed.

I'm yet to see the usefulness of this option (used alone), other than i= n Eric's example, which is what I was after.
If someone has some examples of ls -d usage, _without adding other switches= _ , I'd appreciate it.

I can give a contrived example, but hopefully it will demonstrate that ther= e are some uses cases.

Imagine the following content of a directory:

=C2=A0 =C2=A0 touch a1 a2 a3 b1 b2 b3
=C2=A0 =C2=A0 mkdir b4
=C2=A0 =C2=A0 touch b4/foo

To list everything, typing 'ls' would suffice:

=C2=A0 =C2=A0 $ ls
=C2=A0 =C2=A0 1=C2=A0 2=C2=A0 3=C2=A0 4=C2=A0 6=C2=A0 a1=C2=A0 a2=C2=A0 a3= =C2=A0 b1=C2=A0 b2=C2=A0 b3=C2=A0 b4

Now, I want to see only 'things' starting with 'b'.
Note that by 'things' I mean both files and directories.
>From a purely technical POV, on many file-systems
a 'directory' is just a file, but with a different file-system type= ,
so sometimes technical purists will say 'files' and also mean direc= tories (and similarly, special devices, named fifos, sockets - they are all= 'files').
back to listing things starting with 'b':

=C2=A0 =C2=A0 $ ls b*
=C2=A0 =C2=A0 b1=C2=A0 b2=C2=A0 b3

=C2=A0 =C2=A0 b4:
=C2=A0 =C2=A0 foo

The above might be unexpected output. Because 'b4' is a directory, = ls entered it and listed its content (foo).
If I want to see only list of things (=3Dfiles,directories,everything),
that's where '-d' comes in handy:

=C2=A0 =C2=A0 $ ls -d b*
=C2=A0 =C2=A0 b1 b2 b3 b4

For now, I like your solution: ls -d */=C2=A0 =C2=A0which I'll be using= instead of the find command.

If you use 'ls */' to view directories interactively, that's fi= ne.

If you use it for any kind of scripting (e.g. in a shell for/while loop or = xargs), then it is highly recommended to use 'find' instead of '= ;ls' - a file containing any kind of funky characters (spaces, tabs, ne= wlines, etc.) might confuse your script and cause unintended conseqeunces.<= br>
To save some typing, you can create the following shell function
(e.g. in your '~/.bashrc' file):

=C2=A0 =C2=A0 lsd(){ find ${1:-.} -mindepth 1 -maxdepth 1 -type d -printf &= quot;%f\n";}

And then run 'lsd' or 'lsd DIR' to list the current or the = specified directory.

In scripting, it is recommended to use '-print0' to prevent issues<= br> with files that might contain whitespaces, e.g.:

=C2=A0 =C2=A0 find DIR -mindepth 1 -maxdepth 1 -type d -print0 \
=C2=A0 =C2=A0 =C2=A0 =C2=A0 | xargs -0 -I% echo "Processing directory = %"


Regards,
=C2=A0- assaf



--
Best Regards,
Eddie Sneeh
--001a11c34334ba0212051cfd4a35-- From debbugs-submit-bounces@debbugs.gnu.org Mon Aug 10 23:05:47 2015 Received: (at 21218-done) by debbugs.gnu.org; 11 Aug 2015 03:05:47 +0000 Received: from localhost ([127.0.0.1]:52669 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZOzso-0003XQ-SS for submit@debbugs.gnu.org; Mon, 10 Aug 2015 23:05:47 -0400 Received: from mail-qg0-f42.google.com ([209.85.192.42]:33028) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZOzsm-0003XI-Km for 21218-done@debbugs.gnu.org; Mon, 10 Aug 2015 23:05:45 -0400 Received: by qged69 with SMTP id d69so131333530qge.0 for <21218-done@debbugs.gnu.org>; Mon, 10 Aug 2015 20:05:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=ruT4E3ZPEgXVY7MRI5FNyNY98YUfc+Tltg44wWTW0aM=; b=cpO0XAvW/qz4ugel9+X1tYz1RdOAB6TUU4GsNO30orKNqTRX3NfVlMyTwPGyfQ4rBu vDaDzCR+B9f3UOWjd2dSk/30/OkP6AdRkOZQ4C/PxY4UkV1HrvPQGD+kjd8UtAuve3z8 gcHaDnPzDJqONVoyUdoVIkOIY4VM4prg8VyWMoz5AZgvdPVu3uPVM1lnmWDpfFH3GYM5 CAvZA7cMjXNsSvb6amjlPvvBUAT6AERlJEalV6BYdWhh4xb92scOlgO3T0Hp+CSGIB3T XAD6IHHg1Cj2rYGiksrchGIkBj74DEAorPeybf93n73gCtu/v4q1BoKQmJ11i0vdjABi xvkw== X-Received: by 10.140.89.197 with SMTP id v63mr43707597qgd.97.1439262344216; Mon, 10 Aug 2015 20:05:44 -0700 (PDT) Received: from ix.home (ool-45785e4a.dyn.optonline.net. [69.120.94.74]) by smtp.gmail.com with ESMTPSA id 77sm377777qhw.4.2015.08.10.20.05.42 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 10 Aug 2015 20:05:43 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2102\)) Subject: Re: bug#21218: ls -d From: Assaf Gordon In-Reply-To: Date: Mon, 10 Aug 2015 23:05:42 -0400 Content-Transfer-Encoding: quoted-printable Message-Id: References: <55C57AE2.1010803@redhat.com> <20150810203643.GB24162@gmail.com> To: "Sneeh, Eddie" X-Mailer: Apple Mail (2.2102) X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 21218-done Cc: Eric Blake , 21218-done <21218-done@debbugs.gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) Hello Eddie, > On Aug 10, 2015, at 19:24, Sneeh, Eddie wrote: > I guess what it boils down to is "-d" is a confusing choice of option = for what it really does. "ls --directory" has little to do with = directories, (and adding the word "themselves" to the definition doesn't = really remove much ambiguity), -d lists everything at one level, = non-directories included! I can see why this might be confusing. If there are suggestions for improved wording (while still being concise = and clear), then it might be possible to change the help/man pages. However, regarding the functionality of '-d' - that I'm quite certain = will not change. It is a long-established behavior of 'ls', one that has been standard on = many operating systems and for many years (possibly decades? I'm too new = to know for sure). But perhaps look at it from another perspective: you've mentioned two requests of affecting ls's output: > what I suggested is more intuitive: > ls -d (list directories) > ls -f (list files) > ls -l (list links) and: > The current -d should have been something like: --1level or = --dont_descend or the like. When in fact, 'find' has exactly these options! If you think of 'ls' as: list files, catering to the most common use-cases, and think of 'find' as: list files with maximum flexibility of filters and conditions then the distinction between them becomes clearer. With find you can already performs your requested options: find -type f (list regular files) find -type l (list symbolic links) find -type d (list directories) find -maxdepth 1 (don't descend into sub-directories) and 'find' allows you even more, because you can combine these = conditions in as flexible way as you'd like. for example, to list all directories up to 3 levels down, which start = with 'b', owned by me and are writable: find . -maxdepth 3 -name "b*" -user assaf -writable or, list all regular files in the current directory that have been = accessed in the last 24 hours, and print their name and size: find . -maxdepth 1 -type f -atime 1 -printf "%s %f\n" My point is, the moment you need more than basic listing of files, you should switch from 'ls' to 'find'. This way we can avoid adding more functionality to 'ls' because it = already exists in 'find'. regards, - assaf From debbugs-submit-bounces@debbugs.gnu.org Mon Aug 10 23:58:38 2015 Received: (at 21218-done) by debbugs.gnu.org; 11 Aug 2015 03:58:38 +0000 Received: from localhost ([127.0.0.1]:52686 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZP0hx-0004li-RZ for submit@debbugs.gnu.org; Mon, 10 Aug 2015 23:58:38 -0400 Received: from mailgate4.roche.com ([196.3.50.157]:34811) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZP0hv-0004lZ-Gx for 21218-done@debbugs.gnu.org; Mon, 10 Aug 2015 23:58:36 -0400 Received: from 145.245.200.230 (EHLO mg-int3.roche.com) ([145.245.200.230]) by mailgate4.roche.com (MOS 4.4.4-GA FastPath queued) with ESMTP id CGU47883; Tue, 11 Aug 2015 05:58:34 +0200 (CEST) Received: from 196.3.47.253 (EHLO mail-wi0-f182.google.com) ([196.3.47.253]) by mg-int3.roche.com (MOS 4.4.4-GA FastPath queued) with ESMTP id EXR53777; Tue, 11 Aug 2015 05:58:34 +0200 (CEST) Received: by mail-wi0-f182.google.com with SMTP id hh20so176616138wib.0 for <21218-done@debbugs.gnu.org>; Mon, 10 Aug 2015 20:58:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=jnv3y7Wz2ddRdrrZ4+MNqOqFr8z465ABv5dvZZo+jNI=; b=hYH2SSA5dlFKP2F3Nq5+rdqqs+U1uh4DRmtqHpkjDNSx+la+1d3xkQoUZo9jqOd1Vg hZFLdIizew4YmZrGKQ72oWEsTDzFZBJtvQU1rqa/YUEPw5LUTjKKKzMFjIH333YyQu1v anDyP+ZIRm9YHSmxcsVqJYTA4RvvIzOaYuLmOYA+rkIiVnJiqozw8FExMTdvg8lhIVxs Q8smchTgdv9gysPCU3iaF4rpQ0og87DCjevOrPLnAyvf9kccQgtfOakWrYSkoW+JziVa GvfdknCTsnZrLGH0TNCWRn9iSudCU4gcsZ3u2hhaCwY9Od+RlOslKi7kqUfAXaCX8p5k yjGg== X-Gm-Message-State: ALoCoQmQHFcHI1SBp9scqYk9r4PembXtv7+95DIQXyecIcBoL8b5HTJTDklz10B3hW5NZMVIy9QX9XIhBvblJPHx7nYvzYULllEdq1Ax5a+xysDVjfskIjYffRw9BGpBJnkLNvCVCt9JJMXldO06iwxjqx6fXSjEwg== X-Received: by 10.180.206.143 with SMTP id lo15mr30712653wic.26.1439265514063; Mon, 10 Aug 2015 20:58:34 -0700 (PDT) X-Received: by 10.180.206.143 with SMTP id lo15mr30712601wic.26.1439265513640; Mon, 10 Aug 2015 20:58:33 -0700 (PDT) MIME-Version: 1.0 Received: by 10.27.178.105 with HTTP; Mon, 10 Aug 2015 20:57:54 -0700 (PDT) In-Reply-To: References: <55C57AE2.1010803@redhat.com> <20150810203643.GB24162@gmail.com> From: "Sneeh, Eddie" Date: Mon, 10 Aug 2015 20:57:54 -0700 Message-ID: Subject: Re: bug#21218: ls -d To: Assaf Gordon Content-Type: multipart/alternative; boundary=001a11c38e66adb29b051d011dec X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 21218-done Cc: Eric Blake , 21218-done <21218-done@debbugs.gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) --001a11c38e66adb29b051d011dec Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Thanks again Assaf, please see below... On Mon, Aug 10, 2015 at 8:05 PM, Assaf Gordon wrote= : > Hello Eddie, > > > On Aug 10, 2015, at 19:24, Sneeh, Eddie wrote: > > > I guess what it boils down to is "-d" is a confusing choice of option > for what it really does. "ls --directory" has little to do with > directories, (and adding the word "themselves" to the definition doesn't > really remove much ambiguity), -d lists everything at one level, > non-directories included! > > I can see why this might be confusing. > If there are suggestions for improved wording (while still being concise > and clear), then it might be possible to change the help/man pages. > The problem is the behavior of ls -d is so erratic it's difficult to describe in a concise way. I haven't seen the code or the spec, so my suggestion is based solely on observation (which may or may not be complete). Here's one shot at it, see if you agree or disagree with it: -d: --directory, --donotdescend: Useful only when "*" is part of the argument(s). The same as ls but does not descend into subdirectories. =E2=80=8B =E2=80=8BAdding =E2=80=8B --donotdescend =E2=80=8Bprovides a little bit of =E2=80=8B"credibility" and =E2=80=8B a true meaning to -d because certainly --directory doesn't make much sense. =E2=80=8B I assure you, every user I've worked with over the years that ha= d a question about this was as confused as me.=E2=80=8B However, regarding the functionality of '-d' - that I'm quite certain will > not change. > It is a long-established behavior of 'ls', one that has been standard on > many operating systems and for many years (possibly decades? I'm too new = to > know for sure). > =E2=80=8BYeah, this is not something that I've just discovered suddenly; I = don't know why I decided to "complain" today. =E2=80=8B =E2=80=8BAn unusually slow Monday perhaps. =E2=80=8B I'm fully aware that changing the behavior of ls -d , -f , -l etc.. is not practical, not the right thing to do, but what can be done =E2=80=8B, for the sake of improvement, =E2=80=8B =E2=80=8Bis to provide a clearer definition that reflects the true behavior =E2=80=8B, something along the lines of what I suggested above. =E2=80=8B > > But perhaps look at it from another perspective: > > you've mentioned two requests of affecting ls's output: > > > what I suggested is more intuitive: > > ls -d (list directories) > > ls -f (list files) > > ls -l (list links) > and: > > The current -d should have been something like: --1level or > --dont_descend or the like. > > When in fact, 'find' has exactly these options! > =E2=80=8BMy point is, when a user wants to* list *directory contents, they = think *ls *first*.* "find" is a very useful utility, I like it a lot, and I use it a lot. There are no issues with "find", and this is not about how to use "find", it's about "ls -d". Appreciate the intent and the helpful examples though. =E2=80=8B > > If you think of 'ls' as: > list files, catering to the most common use-cases, > and think of 'find' as: > list files with maximum flexibility of filters and conditions > then the distinction between them becomes clearer. > > With find you can already performs your requested options: > find -type f (list regular files) > find -type l (list symbolic links) > find -type d (list directories) > find -maxdepth 1 (don't descend into sub-directories) > > and 'find' allows you even more, because you can combine these conditions > in as flexible way as you'd like. > for example, to list all directories up to 3 levels down, which start wit= h > 'b', owned by me and are writable: > find . -maxdepth 3 -name "b*" -user assaf -writable > or, list all regular files in the current directory that have been > accessed in the last 24 hours, and print their name and size: > find . -maxdepth 1 -type f -atime 1 -printf "%s %f\n" > > My point is, the moment you need more than basic listing of files, > you should switch from 'ls' to 'find'. > This way we can avoid adding more functionality to 'ls' because it alread= y > exists in 'find'. > > regards, > - assaf > > > > > > > --=20 Best Regards, *Eddie Sneeh* --001a11c38e66adb29b051d011dec Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Thanks again Assaf, please see below...


On Mon, Aug 10, 2015 at 8:05 PM,= Assaf Gordon <assafgordon@gmail.com> wrote:
Hello Eddie,

> On Aug 10, 2015, at 19:24, Sneeh, Eddie <eddie.sneeh@roche.com> wrote:

> I guess what it boils down to is "-d" is a confusing choice = of option for what it really does.=C2=A0 "ls --directory" has lit= tle to do with directories, (and adding the word "themselves" to = the definition doesn't really remove much ambiguity), -d lists everythi= ng at one level, non-directories included!

I can see why this might be confusing.
If there are suggestions for improved wording (while still being concise an= d clear), then it might be possible to change the help/man pages.

=C2=A0The p= roblem is the behavior of ls -d is so erratic it's difficult to describ= e in a concise way.=C2=A0 I haven't seen the code or the spec, so my su= ggestion is based solely on observation (which may or may not be complete).= =C2=A0 Here's one shot at it, see if you agree or disagree with it:
-d: =C2=A0 --directory, --donotdescend: =C2=A0 Useful only wh= en "*" is part of the argument(s).=C2=A0 The same as ls but does = not descend into subdirectories.
=E2=80=8B
=E2=80=8BAdding =E2=80=8B
--donotd= escend
=E2=80=8Bprovides
a little bit of
=E2=80=8B"credibility" and =E2=80=8B
a true meaning to= -d because certainly --directory doesn't make much sense.
=E2=80=8B =C2=A0I assure you, every user I've worked with over the y= ears that had a question about this was as confused as me.=E2=80=8B

However, regarding the functionality of '-d' - that I'm quite c= ertain will not change.
It is a long-established behavior of 'ls', one that has been standa= rd on many operating systems and for many years (possibly decades? I'm = too new to know for sure).

=E2=80=8BYeah, this is not something that I've just discovered su= ddenly; I don't know why I decided to "complain" today. =C2= =A0
=E2=80=8B
=E2= =80=8BAn unusually slow Monday perhaps. =C2=A0=E2=80=8B
I'm fully = aware that changing the behavior of ls -d , -f , -l etc.. is not practical,= not the right thing to do, but what can be done
=E2=80=8B, = for the sake of improvement, =E2=80=8B
=E2=80=8Bis to = provide
a clearer definition that reflects the true behavior
=E2=80=8B, something along the lines of what I suggested above.

=E2=80=8B
=C2=A0

But perhaps look at it from another perspective:

you've mentioned two requests of affecting ls's output:

> what I suggested is more intuitive:
> ls -d (list directories)
> ls -f (list files)
> ls -l (list links)
and:
> The current -d should have been something like: --1level or --dont_des= cend or the like.

When in fact, 'find' has exactly these options!

=E2=80=8BMy point is, when a user wants to= list directory contents, they think ls first.

"find&qu= ot; is a very useful utility, I like it a lot, and I use it a lot.=C2=A0 Th= ere are no issues with "find", and this is not about how to use &= quot;find", it's about "ls -d".=C2=A0 Appreciate the int= ent and the helpful examples though.
=E2=80= =8B

If you think of 'ls' as:
=C2=A0 list files, catering to the most common use-cases,
and think of 'find' as:
=C2=A0 list files with maximum flexibility of filters and conditions
then the distinction between them becomes clearer.

With find you can already performs your requested options:
=C2=A0 find -type f (list regular files)
=C2=A0 find -type l (list symbolic links)
=C2=A0 find -type d (list directories)
=C2=A0 find -maxdepth 1 (don't descend into sub-directories)

and 'find' allows you even more, because you can combine these cond= itions in as flexible way as you'd like.
for example, to list all directories up to 3 levels down, which start with = 'b', owned by me and are writable:
=C2=A0 find . -maxdepth 3 -name "b*" -user assaf -writable
or, list all regular files in the current directory that have been accessed= in the last 24 hours, and print their name and size:
=C2=A0 =C2=A0find . -maxdepth 1 -type f -atime 1 -printf "%s %f\n"= ;

My point is, the moment you need more than basic listing of files,
you should switch from 'ls' to 'find'.
This way we can avoid adding more functionality to 'ls' because it = already exists in 'find'.

regards,
=C2=A0- assaf









--
Best Regards,
Eddie Sneeh
--001a11c38e66adb29b051d011dec-- From debbugs-submit-bounces@debbugs.gnu.org Wed Aug 12 14:35:15 2015 Received: (at 21218) by debbugs.gnu.org; 12 Aug 2015 18:35:15 +0000 Received: from localhost ([127.0.0.1]:54383 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZParq-0005HJ-8u for submit@debbugs.gnu.org; Wed, 12 Aug 2015 14:35:14 -0400 Received: from joseki.proulx.com ([216.17.153.58]:46502) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZParn-0005HB-Kx for 21218@debbugs.gnu.org; Wed, 12 Aug 2015 14:35:13 -0400 Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119]) by joseki.proulx.com (Postfix) with ESMTP id 9BF6D21232; Wed, 12 Aug 2015 12:35:10 -0600 (MDT) Received: by hysteria.proulx.com (Postfix, from userid 1000) id 7466C2DC42; Wed, 12 Aug 2015 12:35:10 -0600 (MDT) Date: Wed, 12 Aug 2015 12:35:10 -0600 From: Bob Proulx To: "Sneeh, Eddie" Subject: Re: bug#21218: ls -d Message-ID: <20150812111806853210700@bob.proulx.com> References: <55C57AE2.1010803@redhat.com> <20150810203643.GB24162@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 21218 Cc: 21218@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) Sneeh, Eddie wrote: > The problem is the behavior of ls -d is so erratic it's difficult to > describe in a concise way. This statement pains me to read. Because it shows that there is still a misunderstanding on ls and ls -d. > I haven't seen the code or the spec, so my suggestion is based > solely on observation (which may or may not be complete). Let me try to describe it. In the beginning that we care about was the Unix file system. In this file system everything is a file[1]. I am going to say that again. Everything is a file. Some files are special files. Most files in /dev are special files such as the block and character devices that immediately people think about. But directories are files too! Directories are simply files in the Unix file system. Directories are another example of special files. The 'ls' command reads directories, which are special files, and lists their contents. The primary purpose of 'ls' is to list directories. Focus on that task. Read the directory file. List it out. Here is an example. In my example I am going to talk classically and simply and acknowledge that some of the system and library calls have been modernized but that doesn't matter because the behavior remains the same. ls / The 'ls' command will have one program argument. That one program argument is the "/" string. The 'ls' program will stat(2) the argument to see if it exists and if it is a directory. If it is a directory then it will treat it specially and call opendir(3) on that string. If that succeeds then it reads the directory and lists out the content. It only does this for directories. In this way directories are treated specially by 'ls'. If the program argument is not a identified by stat(2) as a directory then it is simply printed out normally. If 'ls' is not given any program arguments then it defaults to listing the "." directory. The 'ls' command without arguments: ls Is the same as: ls . This is the same thing. The 'ls' program opens the "." string and gets a handle to the file. It then reads the directory and lists the contents found there. What about shell wildcards? First they are called *shell* wildcards. They don't have anything to do with 'ls' at all. The shell, typically /bin/bash, scans the command line and *replaces* any shell wildcard with the expansion of the file glob. The '*' is called a file glob because it replaces a glob of characters. There are also [...]'s too. This replacement happens at the command line level and happens before the shell invocation of 'ls'. mkdir test cd test touch file1.txt file2.txt file3.txt ls ./*.txt ...the ./*.txt is expanded and replaced by the shell... ls file1.txt file2.txt file3.txt ...the 'ls' command has three program arguments provided by the shell... file1.txt file2.txt file3.txt The 'ls' program has no way of knowing it was invoked with a shell wildcard. The shell replaced that wildcard before ls was launched. All the 'ls' program knows is that it has a list of program arguments. It will walk through each of them in turn and list them out program argument by program argument. Now consider this and this next example. mkdir dir1.d touch dir1.d/file11.txt touch dir1.d/file12.txt ls -log *.* -rw-rw-r-- 1 0 Aug 12 11:33 file1.txt -rw-rw-r-- 1 0 Aug 12 11:33 file2.txt -rw-rw-r-- 1 0 Aug 12 11:33 file3.txt dir1.d: total 0 -rw-rw-r-- 1 0 Aug 12 11:42 file11.txt -rw-rw-r-- 1 0 Aug 12 11:46 file12.txt Not that the files file1.txt, file2.txt file3.txt plus dir1.d were what was listed. The files file11.txt and file12.txt are part of the dir1.d listing. It is subtle but it is really dir1.d that is being listed. That is useful. But it is also often not desired. What has happened? Let's use 'echo' to show what program arguments the the shell is using to invoke the 'ls' command. echo ls *.* ls dir1.d file1.txt file2.txt file3.txt And so here we see that 'ls' has four program arguments. The dir1.d argument is a directory. Therefore 'ls' reads the directory and lists the contents. And in doing so the directory itself is skipped from the listing. What is the permissions on dir1.d? ls -log . total 0 drwxrwxr-x 2 80 Aug 12 11:46 dir1.d -rw-rw-r-- 1 0 Aug 12 11:33 file1.txt -rw-rw-r-- 1 0 Aug 12 11:33 file2.txt -rw-rw-r-- 1 0 Aug 12 11:33 file3.txt Okay. The "." directory was listed. That included the entire directory. But I just want to list the dir1.d directory by itself. ls -log *.d Same as just listing the directory. I just want to see the permissions on the directory and not the contents. ls -log dir1.d total 0 -rw-rw-r-- 1 0 Aug 12 11:42 file11.txt -rw-rw-r-- 1 0 Aug 12 11:46 file12.txt That isn't listing the directory. Because 'ls' has a program argument and it is a directory it is listing the contents of the directory. But I want to list the permissions on the directory itself! How can this be prevented? How can we instruct 'ls' that it should not recurse down into a directory listed as a program argument? If only there were some 'ls' option to prevent it treating directories as special. There is. This is the '-d' option. At least as early as 1979 in V7 the 'ls' command included the '-d' to prevent it treating directories specially. If the '-d' option is applied then 'ls' won't treat program arguments that are directories any different than any other argument. The 'ls' command will simply print it for display the same as any other entry. ls -ldog dir1.d drwxrwxr-x 2 80 Aug 12 11:46 dir1.d Which also allows us to use it this way too. ls -ldog ./*.* drwxrwxr-x 2 80 Aug 12 11:46 ./dir1.d -rw-rw-r-- 1 0 Aug 12 11:33 ./file1.txt -rw-rw-r-- 1 0 Aug 12 11:33 ./file2.txt -rw-rw-r-- 1 0 Aug 12 11:33 ./file3.txt As a quick aside here I always list wildcards ./* or similarly. Because otherwise files starting with a '-' option start character might be confused with being a filename. With ./* that would be expanded to be ./- and that will be avoided. Pedantically I should use '--' to explicitly say I am done listing options. But personally I always use ./* as a personal preference. ls -ldog -- *.* And so we have the '-d' option. The purpose of which is to list the any directory arguments themselves and not their contents. In the V7 docs it described it saying, "If the argument is a directory, list only its name, not its contents (mostly used with '-l' to get status on directory)." The coreutils documentation says: ‘-d’ ‘--directory’ List just the names of directories, as with other types of files, rather than listing their contents. As you can see this has nothing to do with filtering what is displayed. Nor with selecting what is displayed. The '-d' changes how 'ls' treats directories listed as program arguments. If the program argument is not a directory then it has nothing to do. This is why when people try 'ls -d *.txt' it is unlikely to ever be what they want. It is unlikely that file1.txt would ever be a directory. If it isn't a directory then the -d option won't have anything to do anything in that context. The caller may be wanting ls to select based upon the type of the object file but that isn't related to using the '-d' option. And specifically selecting files (finding files) by file type is exactly what 'find' does which is why everyone always redirects such questions to 'find'. Bob P.S. > Assaf Gordon wrote: > > It is a long-established behavior of 'ls', one that has been > > standard on many operating systems and for many years (possibly > > decades? I'm too new to know for sure). Try 40 years. You can read the V7 source and see it there. After four decades it truly is long standing behavior. :-) [1] In Unix everything is a file. Leading to a joke that in the Linux kernel everything is a file system. From unknown Mon Jun 23 07:48:55 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Thu, 10 Sep 2015 11:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator