Skip to content

Instantly share code, notes, and snippets.

@feimosi
Last active March 15, 2017 20:02
Show Gist options
  • Save feimosi/e6c208a2ba6d903a1a3e3e2d16d776f8 to your computer and use it in GitHub Desktop.
Save feimosi/e6c208a2ba6d903a1a3e3e2d16d776f8 to your computer and use it in GitHub Desktop.
Globbing patterns mini-tutorial

Globbing patterns mini-tutorial

Basics

* - any number of characters

# Include all subfolders of react/
ls react/*

? - single character

# Include folders like backup1, backup2, etc.
ls backup?

[] - set of possible characters

# Include man or men or mon
ls m[a,e,o]m
# Include folders starting with 'ma' and ending with any alphabet letter
ls ma[a-z]

[!] - set of excluded characters

# Include anything except man or men or mon
ls m[!a,e,o]m

{} - set of possible terms

# Include 'project/src' and 'project/dist' and 'project/docs'
ls project/{src,dist,docs}

More advanced examples

Select any file ending with test.js from the subfolders:
ls **/*test.js
Select .js files inside direct subfolders of packages folder:
ls packages/*/*.js
Select .js files recursively, excluding node_modules:
ls packages/*/!(node_modules)/**/*.js"

Resources

Utility for testing globbing patterns:
http://www.globtester.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment