GNU bug report logs - #40903
the "ls -R *.pdf" command does not search recursively only current dir

Previous Next

Package: coreutils;

Reported by: Jim Clark <jim.clark.ubuntu <at> gmail.com>

Date: Mon, 27 Apr 2020 14:50:02 UTC

Severity: normal

Tags: notabug

Done: Eric Blake <eblake <at> redhat.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 40903 in the body.
You can then email your comments to 40903 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#40903; Package coreutils. (Mon, 27 Apr 2020 14:50:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jim Clark <jim.clark.ubuntu <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Mon, 27 Apr 2020 14:50:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Jim Clark <jim.clark.ubuntu <at> gmail.com>
To: Jim Clark <jim.clark.ubuntu <at> gmail.com>, bug-coreutils <at> gnu.org
Subject: the "ls -R *.pdf" command does not search recursively only current dir
Date: Mon, 27 Apr 2020 07:25:25 -0700
[Message part 1 (text/plain, inline)]
Greetings,

I found the ls command when used with a pattern does not search recursively.

ls -R *.pdf
only searches the current directory and not recursively.

-- 
Thank you,

Jim Clark
[Message part 2 (text/html, inline)]

Added tag(s) notabug. Request was from Eric Blake <eblake <at> redhat.com> to control <at> debbugs.gnu.org. (Mon, 27 Apr 2020 15:01:02 GMT) Full text and rfc822 format available.

Reply sent to Eric Blake <eblake <at> redhat.com>:
You have taken responsibility. (Mon, 27 Apr 2020 15:01:02 GMT) Full text and rfc822 format available.

Notification sent to Jim Clark <jim.clark.ubuntu <at> gmail.com>:
bug acknowledged by developer. (Mon, 27 Apr 2020 15:01:03 GMT) Full text and rfc822 format available.

Message #12 received at 40903-done <at> debbugs.gnu.org (full text, mbox):

From: Eric Blake <eblake <at> redhat.com>
To: Jim Clark <jim.clark.ubuntu <at> gmail.com>, 40903-done <at> debbugs.gnu.org
Subject: Re: bug#40903: the "ls -R *.pdf" command does not search recursively
 only current dir
Date: Mon, 27 Apr 2020 10:00:52 -0500
tag 40903 notabug
thanks

On 4/27/20 9:25 AM, Jim Clark wrote:
> Greetings,
> 
> I found the ls command when used with a pattern does not search recursively.
> 
> ls -R *.pdf
> only searches the current directory and not recursively.

You are forgetting that globs expand prior to invoking ls.  What you 
have invoked is something like:

ls -R a.pdf b.pdf

which says to recursively list all files starting with a.pdf or b.pdf, 
and descending if any of those files are a directory, but neither a.pdf 
nor b.pdf is a directory, so there is nothing to descend into.

Instead of trying to mess with how globbing interacts with ls, you are 
better off learning how to use 'find', which does recursion and 
filtering as its primary goal.  In this case, you would use:

find . -name '*.pdf'

which gives you a recursive listing of all directories under '.', then 
filters it out to files ending in .pdf.

As the action of globbing is done by your shell and not by ls, there is 
nothing to change in coreutils, so I'm closing this as not a bug. But 
feel free to respond with further questions on the topic.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org





bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 26 May 2020 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 5 years and 23 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.