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
161
votes
13 answers

How can I search sub-folders using glob.glob module?

I want to open a series of subfolders in a folder and find some text files and print some lines of the text files. I am using this: configfiles = glob.glob('C:/Users/sam/Desktop/file1/*.txt') But this cannot access the subfolders as well. Does…
UserYmY
  • 8,034
  • 17
  • 57
  • 71
135
votes
10 answers

Python Glob without the whole path - only the filename

Is there a way I can use glob on a directory, to get files with a specific extension, but only the filename itself, not the whole path?
user825286
120
votes
4 answers

Stop shell wildcard character expansion?

Is there any way for a compiled command-line program to tell bash or csh that it does not want any wildcard characters in its parameters expanded? For instance, one might want a shell command like: foo * to simply return the numeric ASCII value of…
hotpaw2
  • 70,107
  • 14
  • 90
  • 153
119
votes
4 answers

What is the ** glob character?

I have this path in my react gulpfile: var path = { HTML: 'src/index.html', ALL: ['src/js/*.js', 'src/js/**/*.js', 'src/index.html'], JS: ['src/js/*.js', 'src/js/**/*.js'], MINIFIED_OUT: 'build.min.js', DEST_SRC: 'dist/src', DEST_BUILD:…
Jwan622
  • 11,015
  • 21
  • 88
  • 181
113
votes
2 answers

gulp globbing- how to watch everything below directory

This is a pretty dumb question, but I haven't really been able to find a satisfactory answer: How do I use gulp globbing to select all files in all subdirectories below a certain directory? I've tried: './src/less' './src/less/' './src/less/*' None…
Jehan
  • 2,701
  • 2
  • 23
  • 28
104
votes
5 answers

What expands to all files in current directory recursively?

I know **/*.ext expands to all files in all subdirectories matching *.ext, but what is a similar expansion that includes all such files in the current directory as well?
Ramon
  • 8,202
  • 4
  • 33
  • 41
104
votes
13 answers

Is there an equivalent of java.util.regex for "glob" type patterns?

Is there a standard (preferably Apache Commons or similarly non-viral) library for doing "glob" type matches in Java? When I had to do similar in Perl once, I just changed all the "." to "\.", the "*" to ".*" and the "?" to "." and that sort of…
Paul Tomblin
  • 179,021
  • 58
  • 319
  • 408
101
votes
2 answers

Use gulp to select and move directories and their files

I'm currently using gulp to call a bash script that cleans my dist/ directory and moves the appropriate files to the clean directory. I would like this to be done with gulp because I am not sure the script would work on a non *nix file system. So…
makenova
  • 3,579
  • 3
  • 17
  • 20
95
votes
1 answer

Why does gulp.src not like being passed an array of complete paths to files?

I'm attempting to pass gulp.src an array of files that I want it to deal with. This is the array as it stands. ['bower_components/jquery/jquery.js', 'bower_components/superscrollorama/js/greensock/TweenMax.min.js', …
morganesque
  • 953
  • 1
  • 6
  • 4
78
votes
11 answers

List files not matching a pattern?

Here's how one might list all files matching a pattern in bash: ls *.jar How to list the complement of a pattern? i.e. all files not matching *.jar?
calebds
  • 25,670
  • 9
  • 46
  • 74
78
votes
3 answers

python copy files by wildcards

I am learning python (python 3) and I can copy 1 file to a new directory by doing this import shutil shutil.copyfile('C:/test/test.txt', 'C:/lol/test.txt') What I am now trying to do is to copy all *.txt files from C:/ to C:/test *.txt is a…
Johnny
  • 789
  • 1
  • 5
  • 3
78
votes
4 answers

Regular expression usage in glob.glob?

import glob list = glob.glob(r'*abc*.txt') + glob.glob(r'*123*.txt') + glob.glob(r'*a1b*.txt') for i in list: print i This code works to list files in the current folder which have 'abc', '123' or 'a1b' in their names. How would I use one glob…
user1561868
  • 791
  • 1
  • 5
  • 6
77
votes
12 answers

Python glob but against a list of strings rather than the filesystem

I want to be able to match a pattern in glob format to a list of strings, rather than to actual files in the filesystem. Is there any way to do this, or convert a glob pattern easily to a regex?
Jason S
  • 184,598
  • 164
  • 608
  • 970
76
votes
1 answer

grunt (minimatch/glob) folder exclusion

I have a situation where I'm trying to use grunt to lint a codebase, excluding specific folders. grunt uses minimatch (similar to bsdglob) under the hood to match files, but I can't seem to figure out how to do a .gitignore style exclude of a…
Jesse
  • 10,370
  • 10
  • 62
  • 81
70
votes
2 answers

When to use ** (double star) in glob syntax within JAVA

Directly from this Java Oracle tutorial: Two asterisks, **, works like * but crosses directory boundaries. This syntax is generally used for matching complete paths. Could anybody do a real example out of it? What do they mean with "crosses…
Rollerball
  • 12,618
  • 23
  • 92
  • 161