Questions tagged [wildcards]
Globbing means matching files by name patterns containing wildcards.
1,117
questions
0
votes
1
answer
18
views
What wildcards will work with Make's .INTERMEDIATE target?
Isn't there some wildcard I can use for Make's .INTERMEDIATE target?
$ cat Makefile
.INTERMEDIATE: *.csv %.csv #failed
.INTERMEDIATE: north.csv g.csv #worked
Or must I list each and every file each ...
3
votes
2
answers
83
views
zsh completion - ignore executable files with no dot in the name
I am trying to ignore files that are executable and have no dot in them, because when I am coding in C I don't want to open the binary executable files with neovim. Here is what I am trying to achieve:...
-2
votes
4
answers
55
views
gnu grep multiple filters in one regex
RHEL 8, if it matters.
I need to find all the rows in a text file which match these three filters:
cut -f1 -d: .pgpass | grep ^FISP | grep -E 'CDS|TAP' | grep PGS401
FISPCDSPGS401A
FISPCDSPGS401B
...
4
votes
4
answers
223
views
BASH - Find file with regex - Non-recursively delete number-only filenames in directory
I'm wanting to non-recursively delete all files in a directory where each filename contains only numbers, using only a single line of BASH.
I somehow accidentally ran a shell script with commented out ...
3
votes
3
answers
241
views
Find and delete files from unix directory of multiple patterns
I need to delete files from a unix directory having patterns like 'bkp', 'backup', 'bak'.
Basically I want to delete all the backup files.
Files in the directory:
A001.txt_bkp
A001.txt
A002.csv_backup
...
3
votes
2
answers
117
views
Zsh: Copy or Move symlinks to regular files, but not symlinks to directories (or vice versa)
In Zsh,
to copy regular files, I can use cp source-dir/*(.) dest-dir/
to copy directories: cp source-dir/*(/) dest-dir/
to copy everything else, e.g., symlinks, pipes, and devices:
cp source-dir/*(^./...
3
votes
2
answers
170
views
Zsh: enable extended_glob inline in a filename generation glob
In zsh, how can I enable extended_glob inline in a filename generation glob?
Say I want to run ls on all paths not named a, which can be done via:
setopt -o extendedglob
ls ^a
But is there any way to ...
0
votes
2
answers
50
views
'ls *(/)' shows nothing if there is only one empty directory
I have a directory ~/test with two empty directories there: emptydir and emptydir2.
ls ~/test/*(/) shows them both:
~/test/emptydir:
~/test/emptydir2:
But if there is only one empty directory there, ...
0
votes
0
answers
37
views
Fish: To match only files or only folders
In Zsh, to match only files or only folders, I can use *(^/) and *(/) (or *(^/D) and *(/D), if I need to exclude hidden ones).
Is it possible to match only files or only folders in Fish?
1
vote
1
answer
57
views
Fish: To match both dot and non-dot files when wildcarding
Hidden files (where the name begins with a dot) are not considered when wildcarding unless the wildcard string has a dot in that place. E.g., ~/.* matches all hidden files and directories in your home ...
-3
votes
1
answer
21
views
For 'a%' why is one of the results that could be returned 'z6ra'?
For 'a%' why is one of the results that could be returned 'z6ra'?
-1
votes
2
answers
76
views
How to concatenate strings containing asterisks in bash
I have 2 variables:
file1=file1_*.txt
file2=file2_*.txt
The actual names of the files are: file1_FY24Q3.txt and file2_FY24Q3.txt and they change every quarter. I want to concatenate these vars into ...
3
votes
1
answer
469
views
cp -P * vs. cp *(.) vs. cp *(-.)
According to man cp, using cp -P * foo/ means that no symbolic links will be followed:
-P: No symbolic links are followed. This is the default if the -R option is specified.
But how to copy files in ...
0
votes
1
answer
62
views
Matching numbers using Zsh glob operators: difference between '[0-9]' and '<->'
Is there any difference, either practical or not, to use [0-9] or instead <-> to match numbers, when using zmv?
For example, I have tried the following two commands and they seem to work the ...
2
votes
2
answers
201
views
Exclude certain filename suffixes when searching using glob qualifiers
How to exclude one or multiple filename suffixes when searching using glob qualifiers?
Works fine, here we match the filename suffix, not exclude them:
print -rC1 **/*.(txt)(.)
print -rC1 **/*.(jpg|...
3
votes
1
answer
174
views
To understand zmv ## patterns
This is zmv command to non-recursively replace any number of spaces with a single underscore (thanks to Stéphane Chazelas, who helped me with it):
zmv -- '* *' '${f// ##/_}'
And here is a command ...
0
votes
0
answers
75
views
glob star pattern matching man pages [duplicate]
3.5.8.1 Pattern Matching
Any character that appears in a pattern, other than the special
pattern characters described below, matches itself. The NUL character
may not occur in a pattern. A backslash ...
-2
votes
1
answer
94
views
Behavior of truncating multiple slashes in paths stemming from glob pattern matching
From my limited research it seems that in bash, any multiple slashes after a glob pattern are truncated, like so:
echo ////[h]ome////user////Desktop////test////
# outputs ////home/user/Desktop/test/
...
0
votes
1
answer
93
views
zsh: What does (DN) mean?
I have seen that to copy or move directory contents, including hidden files and folders in this directory, to another one, some people use the "mysterious" (DN) thing.
cp -R dir1/*(DN) dir2/
...
2
votes
1
answer
50
views
Untangling pathname expansion and quote removal in echo 'a'*
Shell is: GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
In the current working directory, there are two files:
a file named abc.txt
a file named 'a'bc.txt (created with touch \'a\'bc.txt)
...
0
votes
0
answers
23
views
Exclude a filename suffix from glob match [duplicate]
I've read the documentation but couldn't find the answer to what I wanted to achieve. I have the following files:
$ ls
a a. a.b ab a.c ac
I have the extglob shell option enabled. I want to ...
4
votes
1
answer
555
views
Why does filtering a bash array using negative pattern matching and parameter expansion have unexpected results?
I'm doing a small-ish pure bash script to roll dice; as such I'm having to manipulate arrays. I want to do something akin to a filter operation in other languages: extract some of the things in the ...
-1
votes
1
answer
77
views
As soon as I touch a new file, my ls command with grep stops working [duplicate]
I'm trying to find all the files in my home directory with a specific extension. If I only have one instance of the file extension, the ls command works perfectly fine, but as soon as I touch a new ...
1
vote
1
answer
223
views
Wildcards globbing
Wildcards
An asterisk (*) – matches one or more occurrences of any character, including no character.
Can anyone explain what is this “ including no character” means?
2
votes
1
answer
141
views
Backslash in unquoted variable for glob expansion
Given these six files:
$ touch 'sec*et' 'sec\*et' 'sec\et' secet secret 'sec\ xxx et'
Why backslash in unquoted variable for glob expansion matches only the sec\*et file?
$ v="sec\*et&...
1
vote
1
answer
103
views
Expand a list of files including globs, which are defined in a file
I'm using bash. Suppose I have a file named filelist, which contains a list of files:
stuff/**/*.csv # to keep it simple (without loops), assume just one entry
#*.txt
#foo.md
#bar.bin
And I want ...
0
votes
1
answer
216
views
How to list matching files to a glob pattern?
I've read, and tried, various answers to a question similar to this but they don't work (or at least I can't get them to) for my particular use case.
I have a CI build pipeline that allows a glob ...
0
votes
2
answers
42
views
Changing the response character of the globbing operator ( '**' )
I ran a globbing operator
**
in a directory listing
ls -d "$PWD/"**/
but I noted that after pressing return… and waiting… and waiting… it regurgitated its answer at once, after generating ...
2
votes
2
answers
134
views
Matching negative patterns with bash extglob
Consider I have a set of seven files:
item1_data
item2_data_more
item3_data
item4_data
item5_data_more
other6_data
other7_data_more
and I want to match the three of them that begin with item but do ...
0
votes
0
answers
148
views
tmpfiles.d glob for directories only
According to the documentation, I should be able to use globs to specify a path, however it seems that using /*/ glob for directories isn't supported, is this because this type of glob is part of an &...
0
votes
0
answers
41
views
rsync synchronising a sub-folder while respecting the original folder exclusion rules
I have a bash script which synchronises a source folder to a destination folder in the presence exclusion rules.
something akin to
rsync -l -a -no-g --delete --exclude $PATTERN $SRC $DST
I would like ...
0
votes
1
answer
121
views
C-Shell - stripping wildcards from user input
I am trying to strip wildcards from user input text in a c-shell script.
I realize that the shell automatically expands all wildcards prior to storing the data.
Is there a way to isolate the non-...
2
votes
0
answers
61
views
Pattern list in bash extglob containing a / and a |
Here is a transcript of commands (and their output) that explains my problem:
/tmp/example $ shopt -s
cdspell on
checkwinsize on
cmdhist on
complete_fullquote on
direxpand ...
3
votes
2
answers
787
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
91
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
869
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
104
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
81
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
106
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
92
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
78
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, ...
1
vote
2
answers
200
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
206
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
720
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
59
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
63
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
157
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, ...
3
votes
3
answers
526
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
...