Stack Exchange Network

Stack Exchange network consists of 174 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.

5
votes
0answers
48 views

What would cause glob to list results twice?

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
328 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
51 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
28 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
19 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
3answers
326 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
233 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
136 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
40 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
46 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
77 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
34 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
35 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
47 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
41 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
47 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
35 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
78 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
30 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
137 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
votes
0answers
31 views

Globbing error via Curl on SharePoint

I would like to download all the zip files in a SharePoint directory. The zip files are named in the following format "0111A.zip". I am able to download a specific zip file via this: curl -U ${...
1
vote
1answer
24 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
27 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
55 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
79 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.
1
vote
2answers
43 views

AIX Unix - How to Find and Remove files created between date period, with starting and ending characters?

I'm using IBM AIX Unix and it's limited with command option. I want to implement below filter criteria using find and mtime (which works) option. I would like to remove the files listed with below ...
1
vote
1answer
49 views

how does echo recognize, when it should output list of files or pure text?

I encountered this question in my test: Make echo output all directories that start with a vowel (a,e,i,o,u,e), end with a number and have at least 3 characters. I thought this would be fairly easy, ...
2
votes
6answers
115 views

How do I match only dotfiles in bash? [duplicate]

rm -rf .* will only not end horribly because rm refuses to delete . and ... How do I exclude these special directories from a glob pattern? This is not solved by dotglob since I want to match only ...
1
vote
1answer
58 views

Non-greedy (extended) globs in zsh

I like to do non-greedy globs, but my Google searches hint that this is not supported. Is this the case? If so, why is it the case? For example I'd like to use a non-greedy glob in history expansions,...
2
votes
1answer
70 views

Time range option in shutdown for a user in sudoers

I need to give sudo privileges to a user for shutdown permissions. But the user can only send out a shutdown request with a time of greater than 3 hours. I've been trying by implementing globbing. ...
-3
votes
2answers
86 views

rm -rf ./* deletes content of current directory only partially [duplicate]

rm -rf ./* deleted all content of current directory only partially. Input: MN> cd ~/mydir MN> rm -rf ./* MN> ll Output: -rw-r--r-- 1 MN MN 1025 Aug 1 15:50 .file1 -rw-r--r-- 1 MN MN ...
0
votes
2answers
46 views

Using multiple wildcards in path to run command on all files in directory

I'm trying to run a for loop that copies all files in a directory and then place them in a backup directory. There are multiple sub-directories with varying names so I thought I should use multiple ...
1
vote
1answer
134 views

How does this work ls *[^0-9]* [duplicate]

I am learning the wildcards. I see that ls *[0-9]* would list all the files/directories with numbers in its names so shouldn't ls *[^0-9]* list all the files/directories without numbers in the ...
0
votes
0answers
14 views

How to append a “/*” to the end of a variable with spaces and glob it? [duplicate]

If I have a directory wibble, the following command does what I want: WIBBLE=wibble wc $WIBBLE/* If I have a directory foo bar, the following command does what I want: wc foo\ bar/* But this doesn'...
1
vote
2answers
119 views

Colon character is messing up my pattern match in Bash

I have a variable $line, which can contain any of the following strings: line="READ CACHE IS: ENABLED" line="BLOCKS READ CACHE AND SENT TO INITIATOR = 2489338280" line="ECC REREADS/ ERRORS ...
1
vote
2answers
48 views

How do I search a file for a pattern, then extract part of the pattern or supply a default if the pattern does not exist?

I'm trying to write a script that searches through a pre-made list of running processes across a series of machines. I'm specifically looking for rsyslogd running on those devices, and attempting to ...
1
vote
2answers
58 views

Finding filenames that end in a specific character with or without an extension [duplicate]

I have a bunch of files in a folder that all end in a different version number, like 1, 2, 3, etc. Some of them have extensions, some of them don't. Is there any way I could use a command like ls, ...
3
votes
2answers
399 views

Command works in terminal but not in bash script [duplicate]

If I want to delete everything in the current directory except for "myfile", I can use rm -r !("myfile") But if I put this in a script (called cleanup): #!/bin/bash rm -r !("myfile") I get: pi@...
1
vote
2answers
58 views

Fully show all files in a directory — but with some spacing between them

In CentOS with Bash 3.2.52 I desire to fully-show all files in say current dir: cat * All files' outputs are displaying but they are totally juxtaposed one to another... I lack some cosmetic ...
1
vote
1answer
27 views

How can I increase a number found by wildcard in the previous command? (zsh)

I want to accomplish this: setopt HIST_SUBST_PATTERN echo Ninja_Turtles_2003_S02E05_DVDRip_30NAMA.mkv ^E(0?)^E$((match[1]+1)) # resulting in: echo Ninja_Turtles_2003_S02E06_DVDRip_30NAMA.mkv ‌But I ...
1
vote
2answers
55 views

Make AWK process a huge fileset with a single process

I need to process a large subset of a large set of files with AWK(*) so that it accumulates a set of variables across the files. The straighforward approach of passing multiple filenames to AWK with ...
0
votes
2answers
173 views

Grep Multiple Files with Dates in FileName for Certain range of Dates

I have a bunch of files with filenames like "Logger.2018-08-04_23:59:59.csv" and I want to grep a bunch of them at once, but only in a certain date range, e.g. 8/04-8/17. How can I do this? I tried: ...
3
votes
2answers
44 views

Is there a shorter equivalent to long/path/**/^*.(complex|pattern)~long/path/(bad-1|bad-2)/*(.) that doesn't require repeating long/path/?

It's an zsh extended glob pattern. The point is to match all files with a pattern under a directory hierarchy with the exception of specific sub-hierarchies. The pattern in the title works, but I ...
16
votes
2answers
855 views

What does `.[].foo[]` do in bash? Why does it match `..`?

Look at the following: $ echo .[].aliases[] .. $ echo .[].foo[] .. $ echo .[].[] .. $ echo .[].xyz[] .. $ echo .xyz[].xyz[] .xyz[].xyz[] $ echo .xyz[].[] .xyz[].[] Apparently this seems to be ...
1
vote
1answer
216 views

Glob character within variable expands in bash but not zsh

I'm seeing an issue with zsh where a glob character within a variable is not expanding as I would expect. The following example does a better job of explaining it. $ echo $0 -bash $ echo $HOME/...
4
votes
4answers
273 views

Given two patterns, search specific directories and print last three file names that match each pattern

How can I shorten this command? The goal is to display the latest 3 files that are in the ABC folder and match uvw in the file name, then do the same but match xyz in the file name. I'm looking to ...
6
votes
2answers
828 views

Difference between * and ?* in Bash [closed]

* is roughly a wild card character with a unlimited amount of length. ? is roughly a wild card character for one or zero length. Is there a difference between using * vs ?* when searching for strings ...
5
votes
1answer
100 views

Is there a shopt glob setting or setting combo that behaves like tcsh?

I'm transitioning from being a long time tcsh user to a new bash user (it's way overdue). I wrote a lot of foreach loops in tcsh on the fly on a regular basis, so I learned the syntax for bash's for ...
1
vote
1answer
223 views

Match wildcarded string in case statement using sh shell

I'm having trouble matching a wilcarded string in the sh shell. The code is part of a configure.ac so it usually gets the lamest shell available. I can't count on the Bash shell. The code first ...