1

I'm curious why command ls -pd *[!/] or ls -pd *[!\/] doesn't match all files which don't end with /.

My use case is that I want to list only files inside the current working directory. I know that it's better to use find instead of ls but I want to understand in general is it possible to use / in square brackets in wildcards.

  • You might get more traction on this question on stackoverflow – glenn jackman May 12 '22 at 23:29
  • 2
    In the manual, [Filename Expansion](https://www.gnu.org/software/bash/manual/bash.html#Filename-Expansion) says "When matching a filename, the slash character must always be matched explicitly by a slash in the pattern". Other than that, I can't find anything that says `*/` only expands to directories. Note that the slash is not actually part of the filename. Having said all that, I don't know how to formulate a glob pattern that excludes directories. – glenn jackman May 12 '22 at 23:35
  • perhaps `ls -pd1 * | grep -v '/$'` – glenn jackman May 12 '22 at 23:36
  • @glennjackman thanks for the answer. But it's strange that's it's not documented in the manual or other sources. I can match other special characters with quoting them in square brackets. But back slash doesn't work. – Alex Misiulia May 13 '22 at 10:24
  • 1
    @AlexMisiulia The slash isn't actually part of the filename, it's a delimiter *after* the filename, so it's inherently going to act differently from characters that're part of the filename. – Gordon Davisson May 13 '22 at 18:00
  • @GordonDavisson thanks. Maybe you have some reference to documentation which can describe deeply this topic? – Alex Misiulia May 14 '22 at 20:03

0 Answers0