Categories
Uncategorized

zsh globbing

I love using zsh—it’s full of completely insane features that you wouldn’t even think of using. Until you come across a situation and think: That’s exactly what I need!

Today’s example is recursive globbing. How to pick out all the non-image files in the current directory? I needed to run docs2unix over them. You could come up with some evil find command, but in zsh it looks like this:

  % dos2unix **/*~*.(gif|png|jpg)(.)
  1. **/* picks out all files and directories, recursively.
  2. ~*.(gif|png|jpg) excludes images from that list.
  3. (.) ensures that only files and not directories are chosen.

Easy, peasy. :-)

Update: Even better, case insensitive globbing!

  % dos2unix (#i)**/*~*.(gif|png|jpg)(.)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s