Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 459167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:44:44+00:00 2026-05-12T22:44:44+00:00

I know **/*.ext expands to all files in all subdirectories matching *.ext , but

  • 0

I know **/*.ext expands to all files in all subdirectories matching *.ext, but what is a similar expansion that includes all such files in the current directory as well?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T22:44:44+00:00Added an answer on May 12, 2026 at 10:44 pm

    This will work in Bash 4:

    ls -l {,**/}*.ext
    

    In order for the double-asterisk glob to work, the globstar option needs to be set (default: on):

    shopt -s globstar
    

    From man bash:

        globstar
                      If set, the pattern ** used in a filename expansion con‐
                      text will match a files and zero or more directories and
                      subdirectories.  If the pattern is followed by a /, only
                      directories and subdirectories match.
    

    Now I’m wondering if there might have once been a bug in globstar processing, because now using simply ls **/*.ext I’m getting correct results.

    Regardless, I looked at the analysis kenorb did using the VLC repository and found some problems with that analysis and in my answer immediately above:

    The comparisons to the output of the find command are invalid since specifying -type f doesn’t include other file types (directories in particular) and the ls commands listed likely do. Also, one of the commands listed, ls -1 {,**/}*.* – which would seem to be based on mine above, only outputs names that include a dot for those files that are in subdirectories. The OP’s question and my answer include a dot since what is being sought is files with a specific extension.

    Most importantly, however, is that there is a special issue using the ls command with the globstar pattern **. Many duplicates arise since the pattern is expanded by Bash to all file names (and directory names) in the tree being examined. Subsequent to the expansion the ls command lists each of them and their contents if they are directories.

    Example:

    In our current directory is the subdirectory A and its contents:

    A
    └── AB
        └── ABC
            ├── ABC1
            ├── ABC2
            └── ABCD
                └── ABCD1
    

    In that tree, ** expands to “A A/AB A/AB/ABC A/AB/ABC/ABC1 A/AB/ABC/ABC2 A/AB/ABC/ABCD A/AB/ABC/ABCD/ABCD1” (7 entries). If you do echo ** that’s the exact output you’d get and each entry is represented once. However, if you do ls ** it’s going to output a listing of each of those entries. So essentially it does ls A followed by ls A/AB, etc., so A/AB gets shown twice. Also, ls is going to set each subdirectory’s output apart:

    ...
    <blank line>
    directory name:
    content-item
    content-item
    

    So using wc -l counts all those blank lines and directory name section headings which throws off the count even farther.

    This a yet another reason why you should not parse ls.

    As a result of this further analysis, I recommend not using the globstar pattern in any circumstance other than iterating over a tree of files in this manner:

    for entry in **
    do
        something "$entry"
    done
    

    As a final comparison, I used a Bash source repository I had handy and did this:

    shopt -s globstar dotglob
    diff <(echo ** | tr ' ' '\n') <(find . | sed 's|\./||' | sort)
    0a1
    > .
    

    I used tr to change spaces to newlines which is only valid here since no names include spaces. I used sed to remove the leading ./ from each line of output from find. I sorted the output of find since it is normally unsorted and Bash’s expansion of globs is already sorted. As you can see, the only output from diff was the current directory . output by find. When I did ls ** | wc -l the output had almost twice as many lines.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that Phonegap has an event for back button, but it's only available
I know that this sort of question has been asked here before, but still
As we all know MS added JavaScript formatting to VS 2008 SP1. But unfortunately
I believe Ext.js was using jQuery, but I'm not sure. Does anyone know if
Does anyone know the bare minimum files required for Ext JS 2.2? I know
I know this question has been handeled in similar situations, regarding ASP.Net, before. But
I am bit confused about what OES and EXT means ? I know that
I know there is a couple of topics about that, but the reason I
Know this might be rather basic, but I been trying to figure out how
I know you can not set a key value dynamically, but what about the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.