Questions tagged [wildcards]

Globbing means matching files by name patterns containing wildcards.

Filter by
Sorted by
Tagged with
2
votes
1answer
52 views

zsh completion tag-order matching patterns

Is it possible to use matching patterns instead of ignored-patters in tag-order? I'd like to try a custom limited set of matching completions on the first try without a prefix, like this: $ man <...
2
votes
1answer
30 views

Cycle with exception in bash [duplicate]

How to write a cycle pro all files *.py except a.py? for i in *.py && !(a.py); do python3 $i done
0
votes
1answer
35 views

Globbing and find command. Difference between encapsulating globbing in “ ” and not [duplicate]

Why does find . -name "*.jav" work while find . -name *.jav does not work if there are more than 1 .jav files? What do the " " do and why is the "*.jav" not interpreted as a literal string?
0
votes
2answers
36 views

extglob behavior, particularly when using *(patternList) in bash

I am trying to use extglob, however, after the man pages I'm confused about how *(patternList) operates. Assume I use the following commands: touch A Ax Axxx Axxxx Ay X X.bak x xx xxxx ls ...
0
votes
1answer
162 views

zsh ignore glob if nomatch [duplicate]

To list all docker repositories I need to use an asterisk. But I am forced to add quotes because zsh globbing catches the asterisk. sudo docker image list "hub.local/*" I try aliasing with noglob, ...
1
vote
1answer
70 views

Wildcard does not work with rename when renaming filenames in folder

I have a series of files in a folder with a string in the middle of the filenames starting with _S (_S1, S2, S143 ....), which I need to get rid of/replace with just and underscore. Like this ...
2
votes
1answer
141 views

Globbing with negation in ZSH

I’m trying to get something like ls **/*!(test).rb to expand to all ruby files which do not end with “test”. However, everything I tried so far didn’t help. I tried turning on ZSH’s expanded globbing ...
0
votes
1answer
204 views

Zsh string pattern match to delete spaces

Trying to solve a code-golf problem using zsh, but my regex isn't working correctly. Requirement Given input string $1, delete all spaces immediately to the left of any ! character. Examples: ...
1
vote
1answer
215 views

UNIX/SED - Wildcard in file name

File name is: file_201909091143.csv How to add a wildcard to pull all files that start with 'file' ? #!/bin/bash #cleans blank rows sed -i '/^$/d' file?.csv #wildcard missing UPDATE directory's ls: ...
-2
votes
2answers
53 views

find and copy usage using wildcards

I'm looking to copy a specific folder inside an other one, but I don't have the exact names, for example /volume1/User/save/01/**-**** ?/GROUPES **-****/ **-**** is a number reference that changes ...
-3
votes
1answer
56 views

How do I convert [*] into a regular expression? [closed]

Essentially I need to Ctrl+f (search for) the following string... [*] This means that I want to find everything that matches between (and including) the brackets. What do I substitute the "*" for ...
3
votes
3answers
442 views

Exact number of same characters in word-grep

My task is to find lines with egrep in which first word contains exactly three same letters. I've tried to use backreferences but only found a way to build pattern which finds words builded from 3 or ...
0
votes
1answer
81 views

How to enable “extended_glob” in tcsh?

I am looking to enable 'extended_glob' in tcsh shell and I tried these commands: setopt extended_glob shopt extended_glob But , None of these worked. Can anyone let me know a way to enable this in ...
1
vote
1answer
67 views

Paste & Brace Expansion vs Wildcard

Why does a brace expansion behave differently than wildcard in combination with paste? Example: Assume we have multiple folders, each containing the same-structured tsv and want to create a 'all.tsv' ...
0
votes
0answers
129 views

grep -f not working with file

I have a file with having patterns separated by new line characters. which matches the patterns i want to find from a file. but when i run command grep -f patterns_file words_file It gives no ...
2
votes
2answers
363 views

Wildcards not interpreted by shell script when used with output redirection

Say I have two scripts: script1.sh: #!/bin/bash version=2.6 log_file="$HOME/log-file-version-$version.log" touch $log_file &>/dev/null echo "log to my log file from script 1" >> $HOME/...
2
votes
1answer
141 views

Why doesn't zsh like a file glob like *17*?

I am a relatively new zsh user, and love it 99% of the time. When I try to copy a bunch of files, eg: [I] ➜ ls *17* core.txt.17 info.17 vmcore.17.zst but when I scp *17* xxx:xxx/xxx, I get: ...
4
votes
0answers
131 views

dash not expanding glob wildcards in chroot

I'm working with a copy of Raspbian, installed with pi-gen. Pi-gen runs in a Docker container with a volume for the filesystem, running debootstrap and custom scripts inside a chroot to the volume. I'...
8
votes
1answer
338 views

Why can't I use !(single pattern) in zsh even after I turn on kshglob?

This works in bash: touch a b c echo !(a) If I execute above script in zsh (with kshglob on), it complains: zsh: number expected If I add | after a, it works: echo !(a|) Why?
1
vote
3answers
143 views

Using wildcard in zsh fc command

I have an alias setup in my zshrc to rerun a command with sudo: alias please='sudo $(fc -nl -1)' It works admirably except for the case where I had used a wildcard in the previous command e.g. "rm *....
1
vote
1answer
126 views

bash `case` statement to classify input as non- and integers

summary: I'd like to use a bash case statement (in other code) to classify inputs as to whether they are a positive integer a negative integer zero an empty string a non-integer string Executable ...
1
vote
3answers
256 views

Why does a file move/copy function only move one file at a time when using the “*” wildcard?

function mv1 { mv -n "$1" "targetdir" -v |wc -l ;} mv1 *.png It does only move the first .png file it finds, not all of them. How can I make the command apply to all files that match the wildcards?
5
votes
1answer
480 views

File globbing pattern, !(*example), behaves differently in bash script than it does in bash shell

The following works when pasted directly into my bash terminal (I call bash explicitly, bash version: 4.4.19(1)-release (x86_64-pc-linux-gnu)) for filename in /home/dean/Downloads/!(*example).txt; do ...
4
votes
1answer
402 views

Test if any files that do not match a specific pattern exist in a directory

I am having much difficulty with this. I am trying to test if there exists files in a directory that DO NOT match a given pattern, returning true or false. In this case, files in $dir that don't ...
0
votes
1answer
249 views

lsyncd - How to include specific directories and exclude rest of all directories

I want to include some of the directories in lsyncd process and exclude rest of all directory. I have so many directories in a multisource directory. I want to include only temp and temp1 directory ...
3
votes
3answers
701 views

Remove everything except csv file Bash Script

I would like to delete everything from a folder except csv files I am trying with a bash script and I am getting this error: syntax error near unexpected token `(' This is my script : PATH=/tmp/ ...
2
votes
1answer
84 views

zsh scripting - How do I NOT match a pattern in filename generation?

I'm currently trying to loop through a set of directories, but only the ones I care about. $ ls -d */ cfdpost_statefiles/ p050L0260/ p050L0510/ p060L0390/ p070L0260/ p070L0510/ p092L0390/ ...
0
votes
2answers
29 views

Recursively copying a folder to an empty subfolder

How to copy all the content of the folder /foo/bar, which contains the file /foo/bar/a to an empty subfolder /foo/bar/subfolder without ending up with the file /foo/bar/subfolder/subfolder/a. Doing cp ...
4
votes
1answer
121 views

Does POSIX make not support globs in prerequisites?

I was reading the POSIX 7 Make definition, and I've noticed that prerequisites are almost always described as “files”: The make utility examines time relationships and shall update those derived ...
2
votes
2answers
379 views

Script a Github file download using curl where filename AND path are variable

I needed to script the install of the Digital Ocean CLI " doctl " tool from Github using curl, but there was a problem: The filename varied as it incorporated the version number- so hard-coding it ...
0
votes
2answers
46 views

Displaying file with grep

I expected grep * filename to print every line of filename since I thought * would match every line of this file. $ cat filename first line second line * $ grep * filename #Why won't this print ...
1
vote
2answers
2k views

Bash array with folder paths and wildcards

Given the above folder paths, I am trying to write a script that will delete files older than a certain amount of days. I am trying to use some more advanced techniques than just hard coding the ...
2
votes
1answer
56 views

Grouping directories in `zsh`

Using zsh both of these command produce the same result: ls (dir1|dir2)/dir3/*.txt ls {dir1,dir2}/dir3/*.txt Using bash only the following works: ls {dir1,dir2}/dir3/*.txt So, if I want to list ...
-2
votes
1answer
48 views

Is there any initiative to transition all shell globs into standard regex?

I see many imagination between shell globs (wildcards) syntax and standard regex. Is there (or was there) any initiative to transition all shell globs into standard regex? By that I mean, using ...
1
vote
2answers
178 views

Using wildcards for -group or -user with find command

I'm trying to find owners of files on the system that all start with a specific name, for example [unu@here findtest]$ find . -ls 17295583 0 drwxrwxr-x 2 unu unu 74 Mar 28 03:14 ....
0
votes
1answer
315 views

rm is not working with []

I have files like: ls CONFIG2 DOS DOSCAR KPOINTS PCDAT WAVECAR submit_vasp_beskow.sh CHG EIGENVAL OSZICAR POSCAR XDATCAR vasprun.xml CHGCAR IBZKPT OUT ...
1
vote
1answer
65 views

Subsetting a variable by pattern

I have a delimited file with the following format that I have assigned to a bash variable "foo": echo $foo A 1 hello B 2 hello C 3 hello D 4 world E 5 world F 6 world I am trying to ...
4
votes
1answer
801 views

How is the wildcard * interpreted as a command?

I know how * is interpreted in commands like ls for example. But when trying to run * as a command the shell tries to execute the first file or directory in your working directory. Why is this? How ...
2
votes
1answer
354 views

How to use character classes

In one of my systems, when I run ls [:lower:]*, it will list all files that start with a lowercase letter. In another one, it will give an error: ls: cannot access [:lower:]*: No such file or ...
0
votes
1answer
120 views

Wildcards/Globbing: Are character ranges problematic?

In The Linux Command Line William Shotts claims that character ranges can be problematic. See the relevant excerpt below, emphasis is mine. Character Ranges If you are coming from another Unix-...
1
vote
1answer
1k views

ZSH — Loop files, ignore certain patterns (no ls or find)

I just finished reading an article titled "Why you shouldn't parse the output of ls". I want to loop each file in a directory, and the article states that the following is one of the most basic and ...
1
vote
2answers
87 views

How can one stat an entire directory using a single command line starting with bash -c?

How can one stat an entire directory using a single command line starting with bash -c? This returns all files except for those prefixed with . bash -c "stat /path/todir/**" This returns all files ...
0
votes
1answer
527 views

Bash regex and IFS split

I have the following problem: I want to extract text that is inside brackets from a string (with or without the brackets). My string looks like this: STR="[1] [2][345] [678 9] foo bar" I initially ...
10
votes
1answer
599 views

Is there any advantage in specifying './' in a for loop using a glob?

I was under the impression it could be safer to use ./*.fastq when searching for files ending with .fastq. For example, ./ would prevent capturing the file .fastq. This is obviously wrong, as shown in ...
-3
votes
2answers
101 views

Loop through filenames without eval [closed]

In a shell script, if we want to loop over certain filenames, which we would get by shell globbing, as for example all MKV-files in all sub-directories starting with string "Example" – how can we do ...
2
votes
1answer
161 views

Rearrange pdf pages (swap odd pages and even pages)

I have a pdf and I am in need to replace even and odd pages. If I want to be more specific, I must replace (2n-1) page numbers with (2n) ones (1-->2, 2-->1, 3-->4, 4-->3, and the like). How should I ...
-4
votes
1answer
83 views

What is the result of cd * [closed]

I tried cd * in my terminal (ubuntu), it changes my directory to the first directory listing
6
votes
0answers
149 views

What would cause glob to list results twice? [closed]

System: Raspbian 8 on a Raspberry Pi 3 An errant space in a sudo command caused a bunch of system directories (/bin, /etc, /usr, etc.) to be moved into a subdirectory. I was able to fix it by putting ...
5
votes
2answers
1k views

Find only GUIDs in file - Bash

I have a file that might contain GUIDs (their canonical textual representation). I want to do an action for each GUID in the file. It might contain any number of GUIDs. I have already a file ready ...
1
vote
4answers
79 views

Using an if statement to see if files are in a folder using a wildcard [duplicate]

I have to process multiple files that I dont have the entire name for. I am running an if statement using a wildcard. for example... if [ "ESGSN_*.SMS.EDR" ]; then echo "There are files to ...

1
2
3 4 5
19