Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [wildcards]

Globbing means matching files by name patterns containing wildcards.

3
votes
1answer
33 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
0answers
30 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 ...
0
votes
0answers
33 views

Wildcards and Option Flags [closed]

I have this remove code that deletes files from the system. I need to place option flags and wildcards just like the rm* command. Where will be the best place to put the option flag and wildcard at ...
3
votes
3answers
274 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
23 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
23 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
57 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
82 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
32 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
64 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
35 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
41 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
64 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
66 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
17 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 ...
3
votes
1answer
424 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
42 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
72 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
109 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
38 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
104 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 ...
9
votes
1answer
546 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
86 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 ...
1
vote
1answer
51 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
66 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
83 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 ...
4
votes
2answers
428 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
59 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
vote
1answer
34 views

Listing content from two directories with wildcard

I have a task to list all files from /bin and /usr/bin that contain an e that is neither at the beginning nor at the end. The wildcard is [!e]*e*[!e] and works. (Tested commands cd /bin & ls -l [!...
2
votes
1answer
33 views

WildCard Find Replace CP

I'm trying to replace files that match a particular pattern* on CentOS, but it is not working. I initially wrote: cp example.com/(*)/orm-mysql/build/conf/(*)-conf.live.php example_dev.com/$1/orm-...
7
votes
4answers
570 views

Portable check empty directory

With Bash and Dash, you can check for an empty directory using just the shell (ignore dotfiles to keep things simple): set * if [ -e "$1" ] then echo 'not empty' else echo 'empty' fi However I ...
2
votes
4answers
412 views

Parse all strings of specific length?

I've exported my email archive of 10 years which is very large. I want to parse all the text for any string that is 64 characters long in search of a bitcoin private key. How can I parse strings of ...
3
votes
3answers
241 views

Grep between patterns on separate lines or single line

So what I would need is for grep to match only the text in between (and including) my match pattern. So something like this (don't mind the text, it's just some garble :D): asdgfasd gasd gdas g This ...
0
votes
2answers
66 views

Running multiple command against files matching a brace+glob pattern without repeating it

I would like to run a series of commands against a set of files matched by a braces-and-globs pattern, without copy-pasting the pattern all over the place. I've been trying to do this by putting the ...
0
votes
2answers
396 views

case insensitive, list files in directory, ending in .jpg [duplicate]

I'm trying to write an alias to list all the files in a directory ending in JP(E)G in its various forms. The ones I'm looking for it to recognise are .jpg .JPG .jpeg and .JPEG. Is there a form of ls (...
1
vote
3answers
83 views

Extract a file containing 0|0,0|1,1|0 and 1|1

I have a csv file .Here is how it looks : chr22, Position , A , B , C , D , E 22 , 16050115 , 0|0:404 , 0 , 0 , 0 , 1|1:5 22 ,16050213 ,0|0:403 , 0 ...
0
votes
2answers
35 views

portably perform field-splitting but not other expansions

I used to use unquoted expansion $variable when variable stored compiler flags, but I learned recently that glob metacharacters like * and ? contained in variable are still expanded, e.g. $ f='*' $ ...
1
vote
1answer
368 views

Cannot rm or cp files with a wildcard in name [duplicate]

I have a line like this in my script: rm "$TEMP_DIR/*.txt" It fails with this output: rm: cannot remove 'temp/*.txt': No such file or directory I don't understand why doesn't that work. What am I ...
0
votes
2answers
53 views

An echo operation includes some piece of text it should not include

On a WSL Ubuntu 16.04 (Xenial) with composer I executed: echo 2 * 3 > 5 is a valid inequality It resulted in a file by the name of 5, with the content: 2 composer-setup.php 3 is a valid ...
3
votes
2answers
52 views

Why isn't $foo=* results in an error?

I've learned that the shell expands certain kinds of characters. That's why when writing: $ echo * I get a list of directories and files, let's say I get: Applications Desktop Documents now, Let's ...
0
votes
1answer
53 views

detecting unique lines from log file

I have a large log file and would like to detect the patterns instead of specific lines. for example: /path/messages-20181116:11/15/2018 14:23:05.159|worker001|clusterm|I|userx deleted job 5018 /...
1
vote
1answer
38 views

Restart Apache in a version agnostic way

I use latest Ubuntu 18.04 LAMP but might as well use Debian LAMP or CentOS or something else common. To restart Apache2 I do: systemctl restart apache2 But say "tomorrow" this changes the apache2 ...
-1
votes
2answers
296 views

Find all shell scripts from a folder and execute them in order

I have a folder with a lot of shell scripts to configure my server. My main script is named "setup.sh" and all others scripts are named 0.script.sh, 1.script.sh.... More generally N.SCRIPT_NAME.sh, ...
0
votes
1answer
86 views

bash wildcard expansion even if quoted [duplicate]

The current directory contains file1 and file2. How do you explain this output: [root@server test]# command='*'; [root@server test]# echo $command file1 file2 Why is * expanded? I expect it not to ...
1
vote
4answers
350 views

double check remove on a wildcard

I accidentally removed a bunch of files I wasn't supposed to. I would like to implement some kind of safety net in the future to protect my files. I was hoping that any time I type rm * into the ...
1
vote
1answer
30 views

How to inline expand glob pattern containing character class?

I've come across this question in an attempt to search for a way to inline expand my glob pattern in bash. But in my case the pattern contains some character class. Let say I have 3 files:- abc bbc ...
0
votes
1answer
36 views

Looking for missing files in a directory of files via wildcard inputs [duplicate]

I currently have a directory with 100 files of 4 types, for a total of 400 files. I would like to find which ones are missing. My current script is: for((i=1; i<=100; i++)); do name="File_Type_1_${...
0
votes
1answer
202 views

recursive globbing **/* and */**

I am learning the wildcards recursive globbing and tried $ ls **/* | wc -l 15 $ ls */** | wc -l 15 They output identical results. Is there any distinction between **/* and */**?
1
vote
2answers
105 views

How to match a file name by specifying a prefix substring?

I would like to copy the files, located on a remote machine, whose filenames match a prefix string, on my local machine. I have tried to select only the files whose names start with either massif or ...
5
votes
5answers
2k views

How to copy files whose name contains number from 20 to 32

I want to copy files from the copyDest to pastDest that contain number from 20 to 32. What am I dong wrong? cp -r ~/copyDest/*2[0-9]|3[0-2]* ~/pasteDest Thanks.