LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-01-2021, 08:37 PM   #1
PsychoHermit
Member
 
Registered: Aug 2021
Location: Carson City Nevada
Distribution: Debian Testing
Posts: 137

Rep: Reputation: Disabled
ls -Rd is broken


Hi Folks,


Running ubuntu 20.04.2.0 LTS amd64 on a 7 year old HP ENVY TouchScreen Notebook.

From the ls man page.

Code:
      -d, --directory
              list directories themselves, not their contents

     -R, --recursive
              list subdirectories recursively

glenn@Psycho:~/Desktop$ ls -Rd /
/
glenn@Psycho:~/Desktop$ ls -dR /
/
I believe I have stumbled on a bug in ls.

--glenn
 
Old 09-01-2021, 09:06 PM   #2
GentleThotSeaMonkey
Member
 
Registered: Dec 2016
Posts: 338
Blog Entries: 4

Rep: Reputation: 128Reputation: 128
Look at *source code*, *before* assuming it's a bug.

No, -d stops it from descending. It stops looking into contents.

Yes, adding Recurse=Descend to Don'tDecend is nonsensical

Sometimes, conflicting switches use the last (ps), but not here.

Look thru the source code for ls
(for simplicity, I use mll: https://github.com/mirror/busybox/bl...coreutils/ls.c line 1176

Code:
if (ENABLE_FEATURE_LS_RECURSIVE && (opt & OPT_d))
	option_mask32 &= ~OPT_R; /* no recurse if listing only dir */
Although obvious behavior, I guess you could try to file a RFE for the ls man page.

Last edited by GentleThotSeaMonkey; 09-01-2021 at 09:38 PM.
 
1 members found this post helpful.
Old 09-01-2021, 09:07 PM   #3
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,323
Blog Entries: 28

Rep: Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142
This piqued my curiosity, so I just tested this. The command ls -R works independently, but there does appear to be an issue with ls -d, though my results differed slightly from OP's:

Code:
$ ls --directory
.
$ ls -d
.
This was on Mageia v. 8.

Update:

From the man page:

Quote:
-d, --directory
list directories themselves, not their contents

Last edited by frankbell; 09-01-2021 at 09:08 PM.
 
Old 09-01-2021, 09:23 PM   #4
GentleThotSeaMonkey
Member
 
Registered: Dec 2016
Posts: 338
Blog Entries: 4

Rep: Reputation: 128Reputation: 128
@frankbell: I was editing in more, at the same time you posted

I do always enjoy your contributions!
 
Old 09-01-2021, 10:20 PM   #5
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
The issue is with the pattern.

Code:
# List subdirectories in the current directory
ls -Rd */
# List second level subdirectories in the current directory
ls -Rd */*/
If you want a listing of all subdirecories
Code:
tree -dfi
 
1 members found this post helpful.
Old 09-02-2021, 10:45 AM   #6
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
This is what the POSIX spec says:
Quote:
-d
Do not follow symbolic links named as operands unless the -H or -L options are specified. Do not treat directories differently than other types of files. The use of -d with -R or -f produces unspecified results.
IMO it would be more sensible for -R to be honoured, but the problem with "unspecified" things is that it becomes a matter of opinion as to what the correct thing to do is. One could even make the argument that it should operate like a find . -type d

In most cases you're probably better off just using 'find' anyway.
 
1 members found this post helpful.
Old 09-02-2021, 10:54 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
Quote:
Originally Posted by GazL View Post
IMO it would be more sensible for -R to be honoured,
From my side I do not expect that. ls -ld <something> is used to list that something and nothing else. [again from my side] -R and -d are conflicting. From the other hand in recursive mode (-R) the -d flag is just pointless (or what should that mean?).
 
1 members found this post helpful.
Old 09-02-2021, 11:35 AM   #8
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
I think it essentially boils down to whether one thinks that '-d' should only apply to the command arguments, or the items that it recurses onto when -R is used.

Lots of ways at looking at this, which is why I wish they'd actually specified one.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Recovery broken OS after broken drive DangerSchwob Debian 6 11-02-2020 02:38 AM
Linux Is Broken!!! therion12 Linux - General 15 01-14-2002 12:33 PM
Broken fonts vanarot Linux - General 0 01-11-2002 02:21 PM
Gnome is broken rdaves@earthlink.net Linux - General 3 06-25-2001 11:49 PM
broken su command hoedaivnen Linux - General 0 03-26-2001 07:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration