Questions tagged [glob]

globs, more properly called [shell] patterns, and also known as wildcard expressions, are instances of a pattern-matching language used in many, esp. POSIX-like shells, to match filenames and strings: e.g., *.c is a glob for C source files and matches any file whose suffix (extension) is .c

Glob patterns are distantly related to regular expressions, but have simpler, incompatible syntax and offer fewer features.

Their typical use is to match multiple filenames or paths based on an abstract pattern; e.g.:

  • *.cpp
  • log-user*-[0-9][0-9].gz

A major difference between globs and regular expressions (tag: ) is there are far fewer meta-characters for globbing, and there are no duplication symbols (quantifiers). Most notably, * and ? by themselves match any (possibly empty) sequence of characters and any single character, respectively.

Wikipedia has a page on glob patterns.

On Unix systems, the POSIX pattern notation defines the notation for POSIX-compatible shells.

Generally, it is the shell itself that processes a glob pattern specified as an unquoted argument to a command: it expands it to all matching filenames and passes them as individual arguments to the command given, a process known as filename or pathname expansion.

Note that use of patterns in POSIX-like shells is not restricted to filename expansion: they are also used in parameter expansions (e.g., ${HOME##*/} to strip the directory path from a path) and string-matching operations (such as with case ... esac).

3201 questions
69
votes
1 answer

Glob matching, exclude all JS files

I'm a new user to gulp.js. I'd like to move all of my non-javascript files to a build directory. What I've got right now is this: //Test copy gulp.task('test-copy', function() { gulp.src(['myProject/src/**/*.!(js|map|src)']) …
AlexZ
  • 11,515
  • 3
  • 28
  • 42
67
votes
2 answers

What are the differences between glob-style patterns and regular expressions?

I've encountered situations where only glob-style patterns are supported and full regular expression support is not there, for instance redis keys. I'd like to know the distinction between the two. Also it makes me wonder, is implementing regex…
aamir
  • 3,753
  • 4
  • 23
  • 34
65
votes
1 answer

Node glob pattern for every .js file except .spec.js

I am looking for a better glob pattern for usemin, i want to to find all .js files but exclude the .spec.js files. I have the following solution so far. The solution i have at the…
roughcoder
  • 1,190
  • 1
  • 8
  • 11
64
votes
10 answers

What reasons are there to prefer glob over readdir (or vice-versa) in Perl?

This question is a spin-off from this one. Some history: when I first learned Perl, I pretty much always used glob rather than opendir + readdir because I found it easier. Then later various posts and readings suggested that glob was bad, and so now…
Telemachus
  • 19,459
  • 7
  • 57
  • 79
64
votes
1 answer

Makefile rule that depends on all files under a directory (including within subdirectories)

One rule in my Makefile zips an entire directory (res/) into a ZIP file. Obviously, this rule needs to execute when any file under the res/ directory changes. Thus, I want the rule to have as a prerequisite all files underneath that directory. How…
Mechanical snail
  • 29,755
  • 14
  • 88
  • 113
62
votes
7 answers

Regular expressions in a Bash case statement

I am using following script, which uses case statement to find the server. #!/bin/bash SERVER=$1; echo $SERVER | egrep "ws-[0-9]+\.host\.com"; case $SERVER in ws-[0-9]+\.host\.com) echo "Web Server" ;; db-[0-9]+\.host\.com) echo "DB…
Unni
  • 1,721
  • 2
  • 14
  • 12
62
votes
3 answers

Gitignore all folders beginning with a period

I want to use a .gitignore file to ignore all folders beginning with a period (hidden folders of linux). I can't figure out the syntax, though I'm sure it's simple. How's it done?
cjm2671
  • 18,348
  • 31
  • 102
  • 161
61
votes
6 answers

git: How do I recursively add all files in a directory subtree that match a glob pattern?

I have several .screen files inside /xxx/documentation and its subdirectories that are already tracked by Git. After modifying many of these screen files, I run git add documentation/\\*.screen—as indicated by the first example in git-add's…
Phương Nguyễn
  • 8,747
  • 15
  • 62
  • 96
61
votes
15 answers

glob pattern matching in .NET

Is there a built-in mechanism in .NET to match patterns other than Regular Expressions? I'd like to match using UNIX style (glob) wildcards (* = any number of any character). I'd like to use this for a end-user facing control. I fear that…
dmo
  • 3,993
  • 6
  • 35
  • 39
54
votes
6 answers

node.js glob pattern for excluding multiple files

I'm using the npm module node-glob. This snippet returns recursively all files in the current working directory. var glob = require('glob'); glob('**/*', function(err, files) { console.log(files); }); sample output: [ 'index.html', 'js',…
ke_wa
  • 1,176
  • 2
  • 10
  • 12
54
votes
4 answers

php glob - scan in subfolders for a file

I have a server with a lot of files inside various folders, sub-folders, and sub-sub-folders. I'm trying to make a search.php page that would be used to search the whole server for a specific file. If the file is found, then return the location…
Winston Smith
  • 691
  • 2
  • 7
  • 11
52
votes
8 answers

How to assign a glob expression to a variable in a Bash script?

When the following two lines of code are executed in a bash script, "ls" complains that the files don't exist: dirs=/content/{dev01,dev02} ls -l $dirs When I run the script with the -x option, it appears to be passing the variable within single…
kdgregory
  • 38,754
  • 10
  • 77
  • 102
51
votes
2 answers

Regular Expression usage with ls

I am trying to use ER (Extended Regular Expressions) with ls like ls .+\..+. I am trying to print all files which contains an extension (I know I could have used ls *.*, but I wanted to try using ER). When I run that code I get this error: ls:…
Lucas Rezende
  • 2,516
  • 8
  • 25
  • 34
49
votes
4 answers

Why is cmake file GLOB evil?

The CMake doc says about the command file GLOB: We do not recommend using GLOB to collect a list of source files from your source tree. If no CMakeLists.txt file changes when a source is added or removed then the generated build system cannot know…
Joachim W
  • 7,290
  • 5
  • 31
  • 59
48
votes
11 answers

Can PHP's glob() be made to find files in a case insensitive manner?

I want all CSV files in a directory, so I use glob('my/dir/*.CSV') This however doesn't find files with a lowercase CSV extension. I could use glob('my/dir/*.{CSV,csv}', GLOB_BRACE); But is there a way to allow all mixed case versions? Or is this…
alex
  • 479,566
  • 201
  • 878
  • 984