Questions tagged [wildcards]

Globbing means matching files by name patterns containing wildcards.

Filter by
Sorted by
Tagged with
2
votes
2answers
74 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/...
0
votes
0answers
45 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: ...
1
vote
0answers
41 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'...
7
votes
1answer
222 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?
0
votes
3answers
38 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
51 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
243 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
278 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 ...
3
votes
1answer
50 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
46 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
308 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
32 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
25 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
67 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
146 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
33 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
186 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
40 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
44 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
76 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
123 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
18 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
563 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
69 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
82 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
199 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
41 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
170 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
558 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
88 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
59 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
69 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
89 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
516 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
60 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
36 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
610 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
447 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
315 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
76 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
623 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
556 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
54 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
54 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
58 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
39 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
423 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, ...