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
31
votes
1 answer

Glob / minimatch: how to gulp.src() everything, then exclude folder but keep one file in it

I have a project like this: root |-incl1 |-incl2 |- ... |-excl1 |-excl2 |- .gitignore <-- keep this one |- (other files) <-- exclude them I need to write gulp.src() that will include all folders except excl1 and excl2 but keep…
Borek Bernard
  • 50,745
  • 59
  • 165
  • 240
30
votes
5 answers

PHP get file listing including sub directories

I am trying to retrieve all images in a directory, including all subdirectories. I am currently using $images = glob("{images/portfolio/*.jpg,images/portfolio/*/*.jpg,images/portfolio/*/*/*.jpg,images/portfolio/*/*/*/*.jpg}",GLOB_BRACE); This…
Washburn
  • 417
  • 3
  • 7
  • 13
28
votes
1 answer

What is file globbing?

I was just wondering what is file globbing? I have never heard of it before and I couldn't find a definition when I tried looking for it online.
mr nooby noob
  • 1,860
  • 5
  • 33
  • 56
27
votes
5 answers

Is there an easy way to set nullglob for one glob

In bash, if you do this: mkdir /tmp/empty array=(/tmp/empty/*) you find that array now has one element, "/tmp/empty/*", not zero as you'd like. Thankfully, this can be avoided by turning on the nullglob shell option using shopt -s nullglob But…
derobert
  • 49,731
  • 15
  • 94
  • 124
27
votes
1 answer

typescript tsconfig.json include exclude not working

I have a web project I have folders src/app/shared/models src/app/shared/services src/app/shared/types Each one of those is subfolder that have folders or files inside it, I want to exclude those folders, So i tried: "include": [ "src/**/*" …
Zakk
  • 758
  • 3
  • 11
  • 20
27
votes
3 answers

Python Pandas add Filename Column CSV

My python code works correctly in the below example. My code combines a directory of CSV files and matches the headers. However, I want to take it a step further - how do I add a column that appends the filename of the CSV that was used? import…
specmer
  • 389
  • 1
  • 5
  • 14
26
votes
3 answers

Difference between ** and * in glob matching (.gitignore)

I have the following directory structure and files. pw-spec/ |-- event_spec.coffee |-- event_spec.js |-- integration | `-- service | |-- auth_spec.coffee | |-- auth_spec.js | |-- chat_spec.coffee | |-- chat_spec.js | …
Emil Ivanov
  • 37,300
  • 12
  • 75
  • 90
26
votes
2 answers

Convert WindowsPath to String

redpath = os.path.realpath('.') thispath = os.path.realpath(redpath) fspec = glob.glob(redpath+'/*fits') thispath = os.path.realpath(thispath+'/../../../..') p = Path(thispath) userinput = 'n' while (userinput == 'n'): …
mhemmy
  • 297
  • 1
  • 4
  • 9
26
votes
6 answers

Create regex from glob expression

i write program that parse text with regular expression. Regular expression should be obtained from user. I deside to use glob syntax for user input, and convert glob string to the regular expression internally. For example: "foo.? bar*" should…
Evgeny Lazin
  • 9,193
  • 6
  • 47
  • 83
26
votes
2 answers

Find files in a directory with a partial string match

I have a directory which contains the following files: apple1.json.gz apple2.json.gz banana1.json.gz melon1.json.gz melon2.json.gz I wish to find all of the apple, banana and melon file types. From this SO answer I know that I can find by file type…
LearningSlowly
  • 8,641
  • 19
  • 55
  • 78
26
votes
1 answer

grunt replace all less files into css files

I use grunt to convert all my less files into css files,using this: less: { development: { files: { "css/*.css": "less/*.less" } } } This worked on version 0.3.0, but now that I have upgraded to v0.4.0 it doesn't work anymore. The…
edi9999
  • 19,701
  • 13
  • 88
  • 127
26
votes
3 answers

why is zsh globbing not working with find command?

I have been using zsh globbing for commands such as: vim **/filename vim *.html.erb and so on, but when I type in something like: find . -name *mobile* I get the response: zsh: no matches found: *mobile* Why?
ovatsug25
  • 7,786
  • 7
  • 34
  • 48
24
votes
2 answers

Visual Studio Code Advanced Search Wildcard in Files to Include

I am trying to find a line of code to all my files with a specific file name criteria. I am trying to take advantage the Advanced Search of the Visual Studio Code by putting a wildcard in the files to include field of the search. But I wasn't able…
Rich
  • 3,928
  • 4
  • 37
  • 66
24
votes
2 answers

Are leading asterisks "**/" redundant in .gitignore path matching syntax?

Are there any usages that can't be replaced by equivalents without asterisks? Two consecutive asterisks ("**") in patterns matched against full pathname may have special meaning: A leading "**" followed by a slash means match in all…
Nieralyte
  • 444
  • 1
  • 5
  • 11
23
votes
3 answers

Python glob.glob always returns empty list

I'm trying to use glob and os to locate the most recent .zip file in a directory. Funny thing is, I had the following set up and it was working previously: max(glob.glob('../directory/*.zip'), key=os.path.getctime) Running this now gets me max()…
TheVideotapes
  • 383
  • 2
  • 3
  • 9