Skip to main content

Questions tagged [wildcards]

Globbing means matching files by name patterns containing wildcards.

Filter by
Sorted by
Tagged with
0 votes
2 answers
50 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 ...
Ani's user avatar
  • 3
3 votes
1 answer
367 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 ...
jsx97's user avatar
  • 71
0 votes
1 answer
49 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 ...
jsx97's user avatar
  • 71
2 votes
2 answers
191 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|...
jsx97's user avatar
  • 71
3 votes
1 answer
141 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 ...
jsx97's user avatar
  • 71
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 ...
user599592's user avatar
-2 votes
1 answer
74 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/ ...
GhtGhoster's user avatar
0 votes
1 answer
82 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/ ...
jsx97's user avatar
  • 71
2 votes
1 answer
48 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) ...
yossi-matkal's user avatar
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 ...
k314159's user avatar
  • 447
4 votes
1 answer
532 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 ...
CyberFoxar's user avatar
-1 votes
1 answer
71 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 ...
Gabriel Gavrilov's user avatar
1 vote
1 answer
200 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?
user599592's user avatar
2 votes
1 answer
127 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&...
midnite's user avatar
  • 443
1 vote
1 answer
82 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 ...
lonix's user avatar
  • 1,793
0 votes
1 answer
144 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 ...
Kepboy's user avatar
  • 101
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 ...
The DOuGTrainer's user avatar
2 votes
2 answers
113 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 ...
Chris Davies's user avatar
0 votes
0 answers
114 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 &...
Mathias Sven's user avatar
0 votes
0 answers
38 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 ...
Serge's user avatar
  • 121
0 votes
1 answer
115 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-...
Eric's user avatar
  • 1
2 votes
0 answers
57 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 ...
Happy Green Kid Naps's user avatar
3 votes
2 answers
659 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 ...
user7543's user avatar
  • 256
0 votes
1 answer
81 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 ...
flawr's user avatar
  • 135
1 vote
3 answers
789 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 *} ...
Forivin's user avatar
  • 897
0 votes
1 answer
96 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 ...
algalg's user avatar
  • 107
0 votes
3 answers
77 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 ...
DEKKER's user avatar
  • 968
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 ...
Brad's user avatar
  • 155
-4 votes
1 answer
98 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 ...
Artem S. Tashkinov's user avatar
0 votes
1 answer
83 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: ...
Sebastian Carlos's user avatar
0 votes
1 answer
73 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, ...
DannyNiu's user avatar
  • 620
1 vote
2 answers
166 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. ...
bmitc's user avatar
  • 107
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 !($...
parsley72's user avatar
  • 299
0 votes
3 answers
190 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 ...
Dev Anand Sadasivam's user avatar
2 votes
3 answers
616 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 ...
ksnortum's user avatar
  • 123
1 vote
0 answers
54 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 ...
analog's user avatar
  • 11
0 votes
1 answer
57 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 ...
d-b's user avatar
  • 1,947
0 votes
1 answer
138 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, ...
Debajyoti Kabiraj's user avatar
3 votes
3 answers
515 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 ...
Owen's user avatar
  • 377
2 votes
1 answer
182 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 ...
andrew_ysk's user avatar
2 votes
1 answer
559 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 &...
Pingger Shikkoken's user avatar
0 votes
2 answers
782 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 ...
kkocdko's user avatar
  • 101
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 ...
Csaba Dunai's user avatar
0 votes
1 answer
34 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?
Alee's user avatar
  • 1
0 votes
3 answers
725 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, ...
Vera's user avatar
  • 1
0 votes
1 answer
436 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." ...
user avatar
0 votes
1 answer
44 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 ...
Vera's user avatar
  • 1
1 vote
1 answer
4k 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 ...
Vera's user avatar
  • 1
2 votes
4 answers
175 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, ...
Lilacrail's user avatar
0 votes
1 answer
30 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 ...
ch_esr's user avatar
  • 3

1
2 3 4 5
23