Search code examples
bashfilenamesglobexpansion

Bash globbing - autoexpand for a few specific cases?


I understand that the wildcard * (by itself) will expand in such a way that it means "all non-hidden files in the current folder" with hidden files being those prefixed by a period.

There are two use cases that I would think are useful, but I don't know how to properly do:

  1. How can you glob for... "All files in the current folder, including hidden files, but not including . or .."?

  2. How can you glob for... "All hidden files (and only hidden files) in the current folder, but not including . or .."?


Solution

  • To expand on paviums answer and answer the second part of your question, all files except . and .. could be specified like this:

    {.[!.]*,*}
    

    Depending on your exact use case it might be better to set the dotglob shell option, so that bash includes dotfiles in expansions of * by default:

    $ shopt -s dotglob
    $ echo *
    .tst