Search code examples
wildcardfishdotfiles

How to use recursive wildcards in fish shell for dotfiles and -folders?


The recursive wildcards in fish are extremely useful. But if I want to use it for files or directories with a leading dot it's not working.

For example:

folder
├subfolder
│ └test.txt 
├.subfolder
│ └test.txt
├test.txt
└.test.txt

If I now run ls -a **.txt the output shows only the test.txt files which are not in a folder with a leading dot or are not dotfiles by itself. (output: subfolder/test.txt test.txt)

How can I fix that?


Solution

  • This is fish issue #1568.

    There is currently no short way to do this, the long ways are:

    • Use external programs (like find)

    or

    • Do a more complicated glob like this one:

      ls -a **.txt .*.txt **/.*.txt

    These match, in order: non-dotfiles, dotfiles in the current directory, dotfiles in subdirectories.