2022 Developer Survey is open! Take survey.

Questions tagged [wildcards]

Globbing means matching files by name patterns containing wildcards.

Filter by
Sorted by
Tagged with
0 votes
1 answer
24 views

How to recursively change names of files to match?

I'm trying to change the names of multiple files recursively within a directory, looking something like this: parentdirectory/dir1/foo_1.txt /dir2/bar_1.txt /dir3/foo_2....
user avatar
0 votes
1 answer
63 views

Grep inserting file names from working directory

I have script to do a few jobs: list config XMLs. list which of those XMLs have a match. show what that match is. JENKINS_HOME=/var/lib/jenkins _ALL_JOBS=$( find $JENKINS_HOME/jobs -name config.xml ...
user avatar
  • 1
2 votes
3 answers
87 views

How to list all files including an odd number in a specific number range?

I have a dataset with files named "file000.txt" to "file999.txt". Im aware that I can list all files from 0 to 500 using wildcards with ls file{0..500} And that I can find all ...
user avatar
0 votes
1 answer
37 views

looping through filename [closed]

I need to use a function that has as input multiple files. These files are related by the filename (e.g. dog1_animal.txt, dog2_animal.txt, dog3_animal.txt, cat1_animal.txt, cat2_animal.txt, ...
user avatar
  • 1
0 votes
1 answer
27 views

Usig zsh glob variable not expanding inside alias

I want to list and sort by time, all the files matching a certain pattern and then get only the first 20: ls -laths *.txt | head -20 This works well, for example if I create two files: touch 1.txt ...
user avatar
  • 348
6 votes
4 answers
535 views

grep with Bash-Globbing-like search pattern

I would like to use a very simple pattern matching with a grep-like command. Background is grepping a list of names of VMs, for example a commands that lists just the names of Virtual Machines, where ...
user avatar
  • 111
6 votes
2 answers
136 views

why is zsh not expanding this glob defined inside a function '(:a)'

The second line of the script only works if I trigger glob expansion by executing echo. I can't understand why. Here's the command and it's execution to give some context. Function definition: ~/ cat ~...
user avatar
2 votes
2 answers
32 views

Test fails (correctly) on command line, but succeeds (incorrectly) in script

For the sake of this question, assume that the glob /a/b/c/* produces no matches. This means that the following test should fail (in other words, it should produce a non-zero $?): [[ -n /a/b/c/*(#qN) ]...
user avatar
  • 12.8k
1 vote
2 answers
47 views

Trying to get path into variable; permission denied

I have 20 files of interest in a directory. They can be split into 5 groups, each group identified by a number from 626 to 630 in the file name. For example, there might (hypothetically) be a file ...
user avatar
  • 177
3 votes
1 answer
63 views

ZSH expanded variables in [[ ... ]] do not perform globbing

I have extended_glob set in .zshrc. this works as expected: [[ "value" = [a-z]* ]] && echo "globbed" Prints "globbed". But this does not: foo=[a-z]* [[ "...
user avatar
  • 133
2 votes
1 answer
58 views

How can I make zsh globbing ignore files like .DS_Store

Most of the time I enjoy the combination of (on the one hand) running zsh on a BSD variant in iTerm, but (on the other hand) having the macOS experience available for apps that don't run or don't make ...
user avatar
  • 8,411
8 votes
2 answers
764 views

Avoiding non-zero exit code when running `ls` using multiple patterns

Say I have two possible paths I want to list directories and files under on a Linux machine: /some/path1/ /some/path2/ If I do the following in tcsh, I get 0 exit code, if at least one of path1 or ...
user avatar
0 votes
1 answer
16 views

pom.xml, **/pom.xml, **/**/pom.xml, then **/**/**/pom.xml... What shortcut to target a file we know its name, whatever its depth in directories?

To apply some changes to all my pom.xml files, I'm running these commands: git checkout --theirs **/**/**/**/pom.xml git checkout --theirs **/**/**/pom.xml git checkout --theirs **/**/pom.xml git ...
user avatar
  • 729
0 votes
1 answer
33 views

When does globbing happen (here)

When I pressed enter on this (cd <somewhere>/; ls -gG S09E03* I expected an error from not being a directory with any files matching S09E03* (I've verified that), but the command showed ...
user avatar
3 votes
2 answers
71 views

piping head and tail with globbing

I have several files in the same dir for which I want to print certain lines from a continuous interval, e.g., from 15th to 20th. For a single file, this works head -n20 file.txt | tail -n6, but how I ...
user avatar
2 votes
1 answer
76 views

Shell - negative file globbing

In Bash, to do a negative file globbing I have the following 2 choices. Is there a difference between them ? Both return the same result : $ ls f1.txt f2.txt f3.txt f4.txt $ ls f[!24]* f1.txt f3....
user avatar
-1 votes
1 answer
255 views

Correct usage of "rm" to remove files matching a pattern

If I want to use the rm command to remove all files with the .log extension from a directory, how can I do that? I tried - rm * .log , but I don't know if it works.
user avatar
  • 15
3 votes
2 answers
140 views

how to delete files from list.txt and use a wildcard?

Trying to delete files using a list of the headers and a wildcard. The headers for the files are the same but the endings are different. Not sure how to get the wildcard in there. I was trying to ...
user avatar
  • 33
2 votes
1 answer
156 views

bash ** differs from zsh **, can we change bash behavior?

I have this files tree: a.py b/c.py In Bash, ls -l **/*.py gives b/c.py In Zsh, ls -l **/*.py gives a nice a.py b/c.py Is there a way to change bash behavior to avoid doing ls *.py **/*.py ? PS: I ...
user avatar
  • 125
0 votes
1 answer
288 views

Properly escaping asterisk/glob in (z)sh script

I have the following Problem, I need an environment variable that contains globbing characters as clear text, and I can't seem to escape them. Escaping with backslash works, but for some reason the ...
user avatar
  • 3
5 votes
2 answers
450 views

find - Globbing with disjunction

I've previously written a script that searches a directory tree for .h and .c files and then runs clang-format on them: find $directory -name '*.[hc]' -exec clang-format -i {} \; This works just as ...
user avatar
2 votes
2 answers
559 views

'For' loop won’t iterate over list when path given as argument

I'm practicing shell scripts and am trying to make a simple script that takes a directory as an argument, loops through each file within and prints out its name and size. #!/bin/bash # A practice ...
user avatar
  • 23
1 vote
1 answer
252 views

Correct escaping of wildcard when using jq

The command below works: $ echo '{ "a": [ { "b": "1" }, { "b": "2" } ] }' | jq -r '.a[0].b' 1 But if I try to get the values of all the b elements ...
user avatar
  • 1,151
6 votes
1 answer
525 views

Why can't the extended glob */ be negated with !(*/)?

In bash, if we activate the extglob shell option, we can do fancy stuff like negating a glob (from man bash): If the extglob shell option is enabled using the shopt builtin, sev‐ eral extended ...
user avatar
  • 215k
1 vote
3 answers
34 views

Pass special wildcards characters to set command

I would like to set variables with a special sign "*" using the "set" command $ Q='A * B' $ set -- $Q $ echo "$1 $2 $3" I expect "A * B" Of course, it does not ...
user avatar
1 vote
1 answer
211 views

zsh case-insensitive globbing

Context: macOS Catalina (zsh) This script is to process all JPEG files. This script does not process .JPG files, however it does process .jpg files. top=/Users/user/Desktop/ for file in $top/**/*.jp*...
user avatar
  • 1,104
0 votes
1 answer
34 views

The destination location of command: cp -rf ../path/to/dir * [duplicate]

I accidentally used this command: cp -rf ../path/to/dir * rather than this: cp -rf ../path/to/dir . Now I wonder where the directory is actually copied to! Does anyone know?
user avatar
  • 1,315
1 vote
1 answer
200 views

Converting regular expressions to bash patterns

I have the following regular expressions and want to convert them to bash patterns. itg='^[-+]?[0-9]*$' fxp='^[-+]?[0-9]*[.,]?[0-9]+$' flp='^[-+]?[0-9]*[.,]?[0-9]+([eE][-+]?[0-9]+)?$' I am trying to ...
user avatar
1 vote
1 answer
44 views

How can I use a prefix in the <glob> element of a mime info file?

I have a bunch of files in the form of xyz-timestamp.log, which I want to associate with a different application, than normal log files. I read up on mime types and found out, that I can add a mime-...
user avatar
  • 5,227
2 votes
1 answer
45 views

Debian tcsh not respecting locale for character class expansion

Using Debian 11, tcsh version tcsh 6.21.00 (Astron) 2019-05-08 (x86_64-unknown-linux) options wide,nls,dl,al,kan,sm,rh,nd,color,filec In a directory with two files, a and A, $ echo [a-z] a A This ...
user avatar
  • 41
2 votes
1 answer
272 views

Why is the triple question mark globbing (???) not working with ls?

I am trying to list all files with a name of 3 characters in /usr/bin. ls ??? should do exactly that, but it lists every file in the directory. Note that ls ???? works as intended, showing only the ...
user avatar
  • 31
2 votes
1 answer
118 views

GLOBIGNORE='**/dont_doc/**' does not work!

I wanted to create a glob expression to ignore any file inside a dont_doc directory, but when I tried using using GLOBIGNORE to do it, it did not work: $ GLOBIGNORE='**/dont_doc/**' $ echo dont_doc/** ...
user avatar
16 votes
1 answer
2k views

Splitting a small file into 512 byte segments changes it, but splitting it in 1k segments doesn't

So I'm trying to split a 64MB file FileCarve.001 into 512 byte segments (each block is 512 bytes long). I need to make sure the file has the same data when split into smaller files, so I cat all the ...
user avatar
0 votes
0 answers
21 views

Bash globbing (?) -- unexpected return value in simple program [duplicate]

Why does this program return a? $ cd /tmp $ touch a $ echo '[1a1]' | while read i; do echo $i; done a There is probably some globbing going on. But I don't understand it at all.
user avatar
  • 1,348
0 votes
0 answers
44 views

function exported from .bashrc giving unexpected token for case pattern

I am using Ubuntu 18.04 LTS with Gnu Bash 5. Am getting the following error /bin/bash: printm: line 56: syntax error near unexpected token `(' /bin/bash: printm: line 56: ` +([[:digit:]]))' /bin/bash: ...
user avatar
  • 155
0 votes
0 answers
34 views

Need bash glob to be expanded and keep it ready in the readline

how can bash glob is expanded and keep the cursor ready on the readline so that keep current command from being executed
user avatar
-1 votes
1 answer
68 views

Pattern matching not working with cp?

I have two files I want to copy; A.txt and B.txt. I also have a variable with an expression that should match those two files "*.txt". However running cp $var [destination] or cp "$var&...
user avatar
1 vote
5 answers
246 views

match some or all patterns with awk

I have a small problem with awk multiple pattern matching which I cannot figure out. I have the following awk line: awk '/pat1/{v1=$4; next} /pat2/{v2=$5; next} /pat3/{v3=$6;next} /pat4/{v4=$5; print ...
user avatar
  • 277
2 votes
3 answers
79 views

How can I specify that a path component is optional using zsh globbing?

Say I have the following directory structure: % tree foo foo ├── bar │   └── baz └── baz How can I elegantly match both foo/bar/baz and foo/baz? I.e. how can I make the bar/ component of the path ...
user avatar
  • 14.1k
8 votes
1 answer
768 views

Why doesn't bash interpret the asterisk character when used with xargs command?

As far as I understand, the asterisk character * has a special meaning in Bash and in order to print the literal character we need to either escape it (\*) or quote it ("*" or '*'. However, ...
user avatar
8 votes
5 answers
1k views

Using wildcards to elegantly convert thousands of epub files to mobi

I am executing the below command for 1000 files: ebook-convert <name-of-first-file>.epub <name-of-first-file>.mobi ebook-convert <name-of-second-file>.epub <name-of-second-file>...
user avatar
-1 votes
1 answer
394 views

Event not found in shell expansion [duplicate]

$ touch fux fax fix $ ls f[!a]x zsh: event not found: a]x I want to see fix and fux as output, but not fax. I want to know the exact reason behind this issue. Is this particular issue regarding the ...
user avatar
0 votes
2 answers
77 views

Use ls to list backup files only

I have a large number of "backup" files of the form '#e.xvg.i#', where i ranges from 1 to 60. A file e.xvg also exists in the same directory. For example: e.xvg '#e.xvg.1#' '#e.xvg.2#' ... ...
user avatar
  • 14.3k
1 vote
2 answers
69 views

Why the cache directory gets deleted if not "*" is specified?

I have ZSH as my default shell and I am using OhMyZsh on top of it. Some times I need to delete some files and reset some permissions/ownership so I am working in an alias for it. Lets say I have a ...
user avatar
  • 811
-1 votes
2 answers
68 views

Syntax to select a group of files based on extension?

I have several files in the following form, Group - 1 file1.n001 file2.n002 file3.n003 file4.n004 : : : filex.nx Group - 2 file1.ntemp file2.nreal : :etc In order to remove only files, with ...
user avatar
5 votes
1 answer
285 views

Partially resolve/follow symlinks when globbing in zsh/Bash

Assume I have a file a which is a symlink to b, which in turn is a symlink to c. With zsh's :A modifier, globbing a will result in an absolute path, resolving all symlinks, hence a(:A) will expand to ...
user avatar
0 votes
1 answer
128 views

Escape slashes when sending command output to an array [duplicate]

In my current project, I am trying to take the output from git branch -r to an array in zsh, as follows: % all_branches = ("${(@f)$(git branch -r)}") However, when I run this command, I get ...
user avatar
  • 53
0 votes
1 answer
56 views

Passing arguments into a glob pattern within a script

I have a script called get_numbers.sh, which I want to use to extract data from .pdf files labelled sequentially by date, using pdfgrep. Let me simplify my problem to what I believe are its essentials:...
user avatar
5 votes
1 answer
469 views

/bin/sh: wildcard expansion does not work in script

I am using dash as /bin/sh. In my script, I have following line: SSH_AUTH_SOCK=/tmp/ssh-????????????/agent.* Which is supposed to match file /tmp/ssh-abcdefghijkl/agent.1234. Even when the file ...
user avatar
1 vote
1 answer
498 views

Using a wildcard with "killall" doesn't work other than from /tmp

I have /tmp/bash.sh that contains a script like this: killall name* It works fine if I go to /tmp folder and then run ./bash.sh, but if I go to / then run /tmp/bash.sh or ./tmp/bash.sh it doesn't ...
user avatar

1
2 3 4 5
23