zsh tips: File picking

When you’re working on your shell, you immediately get in contact with files, directories and therefor paths. Most of the time there are simple paths, but sometimes it gets exciting and you need to defined multiple files. Instead of defining them manually on the shell, you can work with placeholders in form of asterisks.

Asterisks in file paths (e.g. data/*.txt) are called globs, and they’re really important for file picking. Globs are omnipresent in most modern shells, but because we’re talking about zsh, we can imagine that globs on zsh are on steroids as well!

Simple globs: File picking based on filenames

Of course you might already know simple globs like these:

But with zsh you can go further:

Glob qualifiers: File picking based on metadata

Glob qualifiers will help you to pick files/folders based on metadata (i.e. inode). If you get used to it, you’ll get more productive thanks to a really short syntax. This also means by using glob qualifiers, you can skip the use of the good old fashioned  find:

Modifiers

To keep it simple: If you get used to modifiers in zsh, then you can skip variable substitutions for paths, and you don’t even need to call dirname and  basename in your scripts:

 

Leave a Reply

Your e-mail address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.