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
329 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
32 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
60 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
43 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
31 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
40 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
536 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
80 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
33 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
62 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
74 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
353 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
57 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
30 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
26 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
513 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
374 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
184 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
52 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
148 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
79 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
114 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
49 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
50 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
50 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
36 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
170 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
52 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
253 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
28 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
30 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
115 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
96 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
65 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
50 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
137 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
70 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
106 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
105 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
63 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
228 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
181 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
50 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
73 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
479 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
59 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
29 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 ...