0

I use this to list all text files in d:\ root:
ls d:\*.txt
This to list all text files in all sub-directories:
ls d:\*\*.txt

How can I list all text files in the root AND in all sub-directories using ls?

This doesn't work:
ls d:/{,**/}*.txt

edit: in ls not in find, grep, awk, sed or whatever other search command

5
  • Possible duplicate of List files recursively in Linux CLI with path relative to the current directory Commented Feb 12, 2019 at 19:50
  • Why is this tagged linux, but using paths that look like d:\....?? Commented Feb 12, 2019 at 20:09
  • NO duplicate! This is about 'ls'. I know there is the 'find' and grep command but in my question I write about 'ls'. :(
    – Reman
    Commented Feb 12, 2019 at 20:09
  • @WilliamPursell, good question. I'm using windows subsystem for linux (=linux on windows 10).
    – Reman
    Commented Feb 12, 2019 at 20:14
  • @jww I know. I doubted in the beginning. Could not find a better site.
    – Reman
    Commented Feb 15, 2019 at 10:47

1 Answer 1

1

You can try ls **/*.txt. This is worked in zsh.

or

ls $(START_DIR)/**/*.txt

11
  • Yes that works but there is no way to indicate the d:\ directory (the start directory)? --> Edit: It doesn't work.. It doesn't include the text files in root.
    – Reman
    Commented Feb 12, 2019 at 20:11
  • just append the start directory in front. ex. ls ~/home/*/**/*.txt
    – J.Z
    Commented Feb 12, 2019 at 20:15
  • Sorry, it doesn't work. I made a mistake. It doesn't include the text files in root.
    – Reman
    Commented Feb 12, 2019 at 20:17
  • 1
    @Reman Which shell are you doing this in? Bash requires you to shopt -s globstar first Commented Feb 12, 2019 at 20:40
  • 1
    They do not share syntax, even if some commands are similar. Please choose one to ask about. Commented Feb 12, 2019 at 21:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.