0

What is a bash glob pattern that will match all files and directories in the current directory, except for . (current directory) and .. (parent directory)?

e.g., given the following files/directories:

.
..
.my_dot_directory
.my_dot_file
my_directory
my_file

I want a glob that will return:

$ ls -d <my_glob>
.my_dot_directory
.my_dot_file
my_directory
my_file
Rob Bednark
  • 25,981
  • 23
  • 80
  • 125
  • It would be much easier just to check for those special cases in the code rather than try to make a complicated glob. – Tim Roberts Jun 18 '23 at 23:54
  • * .??* handles 99.9% of cases. – Joshua Jun 18 '23 at 23:55
  • `(shopt -s dotglob; ls -d *)` – jhnc Jun 18 '23 at 23:55
  • for a shell without nullglob, I think you'll always have to check anything was matched (eg. `*` didn't just return `*` and that there isn't actually a file literally called `*`) – jhnc Jun 19 '23 at 00:02
  • Also see the [dotglob](https://mywiki.wooledge.org/glob#dotglob) section in [glob - Greg's Wiki](https://mywiki.wooledge.org/glob). – pjh Jun 19 '23 at 00:56

0 Answers0