thiagowfx's avatar

¬ just serendipity 🍀 (not just serendipity)

bash: glob hidden files recursively

• 102 words • 1 min • updated

⚠️ This post is over one year old. It may no longer be up to date or relevant. Opinions may have changed.

Assume you make a huge change to your git repository, that spawns several file formats – cpp, java, javascript, python, etc.

In the end you want to revert the javascript changes, for the sake of splitting your commit into self-contained chunks1.

I like the following approach2:

shell
% git checkout -- **/*.js

Caveat: It does not include hidden files, or files in hidden directories. Unless…you set the dotglob option:

shell
% shopt -s dotglob

Note that shopt works in bash, alas not in zsh.


  1. https://sscce.org/ ↩︎

  2. In theory, this is a pre-requisite: shopt -s globstar. In practice, it should be the default behavior. ↩︎