Questions tagged [wildcards]
Globbing means matching files by name patterns containing wildcards.
1,083
questions
3
votes
1
answer
176
views
Command line glob to view multiple images using ImageMagick's display
How can I open multiple images files using ImageMagick's display command? If I enter say display *.png in a directory containing multiple PNG files, only one is displayed. I think I'd prefer them to ...
0
votes
1
answer
33
views
How to reuse matched value in bash globbing? [duplicate]
I was wondering whether it is possible to reuse whatever was matched in a path with globbing? (Just as it can usually be done with regex substitutions?)
I'm aware that there are other solutions for ...
1
vote
3
answers
202
views
How to do wildcard/glob expansion when the pattern and the resolved pathes contain spaces?
I need to expand some pathes using a POSIX sh or Bash:
Here are two example patterns (I chose overly complicated patterns on purpose):
$ npm pkg get workspaces | jq -r '.[]'
apps/app*
lib/{be,fe *} ...
0
votes
1
answer
46
views
Reducing repetition in sudoers file
I have a sudoers file, that allows a user to run sudo commands without a password (mostly to manage specific services). I would like to drastically reduce repetition throughout the config:
Here's a ...
0
votes
3
answers
54
views
How to expand variable inside single or double qoutes
I have 2 systems and they have the same directory strcuture. I want to execute a couple of commands on local system and the same on remote system.
I use the wildcards so when I have a new version of ...
4
votes
2
answers
1k
views
cp some/path/**/*.h is not including .h files at all depths
I'm trying to copy all .h files in a directory and all subdirectories into another folder using the copy command:
cp --parents -r tensorflow/lite/**/*.h libtensorflowlite-2.13.0-linux/include
The ...
-4
votes
1
answer
76
views
Expand a wildcard matching single directory/file
This works beautifully in BASH:
$ where=/sys/class/backlight/*
$ echo $where
/sys/class/backlight/intel_backlight
However when put in the POSIX script with /bin/sh as an interpreter, this doesn't ...
0
votes
1
answer
58
views
Bash: Difference between "Pattern Matching" and "Filename Expansion" in the context of parameter expansions that do matching
Edit: Question ansewered by Gordon Davisson's comment
I was reading the GNU Bash manual, and I noticed that there are basically three types of "Parameter expansion" that do pattern matching:
...
0
votes
1
answer
55
views
Is KornShell pattern a regular expression?
KornShell pattern extends POSIX shell "glob" patterns (i.e. *, ?, etc.) with repetition specifiers such as *(...), +(...), as well as negation among many nice features.
In a hobbist project, ...
0
votes
2
answers
62
views
Getting an array of files built from include array and exclude array containing globs
I am wanting to do the following:
Define an array of globs that specify a base collection of files to include in a process.
Define an array of globs that specify files to exclude from that process. ...
11
votes
1
answer
1k
views
Syntax error when "cp" statement with extended globbing options is moved to an "if" block
Having some trouble doing a copy in Bash. This works fine:
# Enable extended globbing and include filenames beginning with a '.'
shopt -s extglob dotglob
# Copy git repo to expected place
cp -r !($...
0
votes
3
answers
102
views
How to find linux commands using wildcards ? and * [duplicate]
In my Linux machine I am able to find commands starting with ls by
$ ls<TAB-key>
I get the results like this,
ls lsb_release lscpu lshw lsipc lslogins lsmod ...
2
votes
3
answers
171
views
How do you match zero or one character in the "-name" option of the "find" command?
For instance, want to match all files in this directory and sub-directories that end with .ly or .ily. So far, find . -name "*.*ly" -print is the closest I can get but this could ...
1
vote
0
answers
44
views
Files and directory missing after mv with bash extglob inverse match
Attempted to move all files and directories not ending with .srt to the parent directory by using these commands:
shopt -s extglob
mv !(*.srt) ..
Checked dir contents with ls and everything looked ...
0
votes
1
answer
34
views
When processing multiple files, can output be redirected to a separate file for each input file?
I execute something like this:
% command *bin > log.txt
*b expands to a.bin, b.bin, c.bin.
I would like stdout from each file to end up in a separate log.txt (or rather, a.txt, b.txt, c.txt). How ...
0
votes
1
answer
53
views
How to copy files from a list without extension to a different folder?
I have a text file that contains a list of ids of files without any extension now I need to copy those files mentioned in the list
head 01cBC.txt
EE87786
EE87787
EE87788
EE87789
EE87790
EE87791
Now, ...
0
votes
0
answers
22
views
globbering without error [duplicate]
I'd like to globber for files in a bash loop, something like this:
for file in filepattern???; do
# some command
done
But, if there are no files that match filepattern???, then this loop executes ...
3
votes
3
answers
439
views
in zsh, strip and add a suffix in a single glob pattern
Suppose I have a file named foo.md.md (the reason for the double suffix will become apparent).
$ print *.md(om[1]) # Get the most recent .md file
foo.md.md
$ print *.md(om[1]:r) # Strip the suffix
...
2
votes
1
answer
82
views
to search for files with 2 (full or partial) keywords content (txt files) in a folder and sub folder and files with specific filename
I just want to share this, and hoping will get more similar tool.
I got a directory of text files.. i need to search for the files with 2 (partial) words in it.. the keywords are in random order, but ...
2
votes
1
answer
207
views
for loop over directory glob with space won't work
I'm attempting to recursively work on directories and files, that are mirrored at second location
The function I defined is:
#!/bin/bash
set -e
shopt -s nullglob
shopt -s dotglob
dom() {
echo &...
0
votes
2
answers
224
views
BusyBox's tar --exclude doesn't exclude
Extract a tar file with content dir1/dir2/file, using --exclude dir2 switch. The gnu tar excluded but busybox's tar doesn't.
Use --exclude dir1/dir2 works fine, but why? Is there a way to exclude any ...
14
votes
9
answers
2k
views
How to select a sub-range of the files in the current directory in a script/on the command line, based on e.g. alphabetical order?
In a file manager you can usually select a file, then hold Shift and select another file. Every file in between will be selected.
I want to do the bash / zsh equivalent of this.
I.e: I want to give 2 ...
0
votes
1
answer
32
views
Listing filenames that contain, but does not begin or end with a certain character sequence
I want to list all filenames that include "2022" but exclude those that begin with it or end with it. What commands would work for this?
0
votes
3
answers
435
views
Glob pattern matching comma separated numbers
I want to write a glob pattern to match numbers separated by commas. What would the pattern be like?
Here are some examples
5
5,8,13
Have started with the following, but there some problem with it, ...
0
votes
1
answer
151
views
Using globs in the sudoers file
The following man page states that, "sudo allows shell-style wildcards (aka meta or glob characters) to be used in host names, path names and command line arguments in the sudoers file."
...
0
votes
1
answer
41
views
Eliminating ^ and $ in pattern matching
Am using the following regex condition, with ^ and $ to represent the start and end of the given pattern.
if [[ "$1" =~ ^[[:digit:]]+$ ]]; then
I have also written the equivalent glob ...
0
votes
1
answer
779
views
Glob and regex matching
Bash has two types of pattern matching, Glob and Regex. The general rule of usage seems to be that 1) the simpler glob is done to search filenames 2) regex is used for searching text.
Glob uses the ...
2
votes
4
answers
142
views
Print two remembered patterns, and only the non-alphanumeric characters between them
I'm using GNU sed 4.7 on Debian 11.
I have a file with many lines, all of which have a first string in curly brackets at the beginning of the line, a final string in @ chars at the end of the line, ...
0
votes
1
answer
26
views
extract last part of filename using echo - having assigned variables using wildcards
I am trying to extract parts of a filename, where I want to extract everything after the first _
and I have found a working solution, see below
file=22NGS71294_S191_R1_001.fastq.gz
echo $file
...
0
votes
2
answers
354
views
Bash regex named capture groups with backreference?
I want to do below -
bash-shell>echo (*).prop ; echo \1
Obviously above does not work. But want to know if it is possible and what would be the working equivalent.
I want * (for shell this the ...
1
vote
0
answers
114
views
What does it mean when a file isn't detected with a wildcard search? [closed]
I have three files in a folder: trace-0.fits, trace-1.fits, trace-2.fits.
When I run:
ls trace-?.fits
Only trace-0.fits and trace-2.fits are detected. But:
ls trace-1.fits
Detects trace-1.fits, as ...
1
vote
2
answers
58
views
How to remove similar folder from multiple locations in terminal
I have a folder 'reg_standard' nested within 68 different folders that I want to remove. The path to this folder looks something like:
/Volumes/.../sub-???/run_?.feat/reg_standard
where '?' is a ...
0
votes
2
answers
85
views
Wildcard doesn't work in a "for f in ..." for a different directory (and partition)
testingfilesizecheck.sh: line 6: /media/doctor/123A123E1A123456/Users/Tim/Downloads/PokemonRed/Binary House/Final Structure Directory/Category/*
I am using the command for f in "/media/doctor/...
1
vote
1
answer
72
views
bash `if` block contents fail to execute due to syntax error on extended glob pattern in MacOS
Short Version:
When extended glob is turned on inside a bash if block on my Mac, the entire block fails with a syntax error on any extend glob pattern contained in the block, even if it follows the ...
9
votes
1
answer
1k
views
What is the meaning of `*(1)*` in a command?
Why use of *(1)* removes everything from a directory? Then how to select all files that has (1) in the middle of it's name?
The command used is rm *(1)* or rm -rf *(1)* (don't remember exactly). It ...
1
vote
4
answers
188
views
How can I remove files that have an unknown number in them?
I have some code that writes out files with names like this:
body00123.txt
body00124.txt
body00125.txt
body-1-2126.txt
body-1-2127.txt
body-1-2128.txt
body-3-3129.txt
body-3-3130.txt
body-3-3131.txt
...
1
vote
1
answer
272
views
How to use "find" with a wildcard before and after a term?
I'm trying to delete all files in a directory (recursively) with a name that contains a string. Ultimately I want to do this:
find . -type f -name '*.m3d*' -delete
But before running the delete, I ...
2
votes
2
answers
157
views
How does this glob expression remove colons?
Say we have a file called "Hello World: The easiest program" and its name is saved in a variable called "title".
I want to match this with glob pattern matching, but remove the ...
3
votes
1
answer
166
views
Why am I not able to use * with touch in path? [duplicate]
This is the output of tree:
[xyz@localhost Semester1]$ tree
.
├── Eng
├── IT
├── IT_workshop
├── LA
├── OS
├── OS_lab
├── Psy
├── Python
└── Python_lab
9 directories, 0 files
I want to create 3 ...
10
votes
4
answers
2k
views
In Bash, how can I rm files against a wildcard while supplying more than one exception?
I have the following list of files:
main.acn
main.acr
main.alg
main.aux
main.glg
main.glo
main.gls
main.ist
main.lof
main.log
main.lot
main.nlo
main.out
main.pdf
main.tex
main.toc
I want to rm all ...
0
votes
1
answer
1k
views
find: using wildcard in -name pattern
I have a simple wrapper script to play videos, where my script tries to find subtitle file to a given video file (if it exists). Given video name, I am looking for same name, only ending in .vtt ...
3
votes
2
answers
612
views
gunzip multiple gz files with same compressed file name in multiple folders
I have a directory where there are multiple folders, each folder contains multiple .gz files with the same zipped file name "spark.log". How can I unzip all of them at once and rename them ...
1
vote
1
answer
324
views
Bash to select by wildcard any filename without extension
How bash select by wildcard any filename without extension as doing it end in falure? e.g.
$ ls /source/c
m m.asm m.c m.d m-0 m-1
$ cp -ru /source/c/*. ~/Downloads/c
cp: cannot stat '/source/c/*.': ...
3
votes
1
answer
231
views
Loop for each file in directory but not throw error when no files present
I want to load aliases based on the files in .profiles/ dir.
for profile in ~/.profiles/*; do
for file in ~/.s1n7ax/$(basename $profile)/alias/*; do
include "$file"
done
done
...
3
votes
1
answer
117
views
zsh glob qualifier with negated null glob works like it should with null glob
Note: Please don't respond about this being a XY situation. I am trying to understand how a globbing pattern works, not trying to achieve a specific result. Am also not interested in other ways to ...
1
vote
1
answer
80
views
TAB expanding filenames after make command in bash
I'm preparing a makefile for converting org files to markdown files with the use of pandoc. Its content looks like this (note that conversion rule is just for a reference):
%.md: %.org
pandoc -t ...
1
vote
1
answer
237
views
What is the point of using asterisk wildcard with recursive operation?
i'm reading LPIC-1 PDF's. It says:
In general to copy all the contents of a directory we use:
cp -r SOURCE_PATH/* DEST_PATH
But i can't understand why -r option itself without * is not enough? It ...
0
votes
1
answer
35
views
`for in` command filename expension issue [duplicate]
I have a bash script with:-
for i in *.x *.y *.z *.a *.b *.c
do
echo "$i"
done
If there are no files matching the pattern *.y then the variable i has the value *.y. When this happens, ...
1
vote
1
answer
62
views
How to do pattern matching on `.bashrc` for file extensions
I'm modifying my .bashrc: I want to make it so that .zip,.tar and .tar.gz files (and maybe more later down the road) are shown with a red color. Thing is, I want to match for all those files once. So ...
0
votes
1
answer
39
views
How Can I Interpret Quoted Wildcards
I am writing a shell script and I need to interpret quoted wildcards.
"R Programming*"
I do not want the * asterisk to be taken literally.
I want it to be interpreted as a wildcard.
"R ...