Globbing is a way to match sets of paths without explicitly specifying paths. For example, the * glob would match all paths in a directory.
Questions tagged [globbing]
53 questions
39
votes
5 answers
How to expand * on Bash command line
I understand that if you type ls * it is actually expanded to ls a b c when the current directly has files a, b and c.
I was wondering if there is a way to expand this before I hit enter. Similar to how Ctrl+X works, or tab complete works.
So to…
bramp
- 508
- 1
- 4
- 7
28
votes
2 answers
Does bash's * match files in alphanumeric order?
I want to concatenate a bunch of files together in filename order.
Is it safe to assume that this will give me them in alphanumeric order?
cat *
i.e. the same order that ls gives.
therefromhere
- 8,132
- 10
- 40
- 43
24
votes
2 answers
how do I correctly negate zsh globbing expressions?
I want to list all files but those ending with owp: Hence I tried:
ls -l *.(^owp)
zsh: unknown sort specifier
ls -l *(^owp)
zsh: unknown sort specifier
ls -l *[^o][^w][^p] # does not work either, missing some files
none worked. How do I…
math
- 2,507
- 7
- 27
- 43
22
votes
7 answers
Will rm -rf * remove all files/folders in the current directory?
Will rm -rf * remove all files/folders in the current directory ? I want to make sure the wildcard * won't move up in upper directories and erase all my filesystem. :D
I remember doing chmod 777 .* -R to chmod hidden files and it chmoded all my…
Olivier Lalonde
- 9,327
- 7
- 28
- 33
12
votes
2 answers
Linux Bash Shell - File globbing specific range?
I have a bunch of files in a folder:
spreadsheet700.xls
spreadsheet800.xls
spreadsheet850.xls
spreadsheet1005.xls
spreadsheet2400.xls
how can I use file globbing to select files that numbers end in 700 or higher, but less than 1000 and put them into…
BubbleMonster
- 400
- 4
- 17
12
votes
3 answers
How to delete all hidden .swp files from terminal
How can I delete all .swp files? I tried rm *.swp but I got rm: *.swp: No such file or directory
rwxr-xr-x 16 teacher staff 544 Jan 17 13:19 .
drwxr-xr-x 19 teacher staff 646 Jan 16 12:48 ..
-rw-r--r-- 1 teacher staff 20480 Jan 17…
shinokada
- 2,265
- 6
- 32
- 46
11
votes
2 answers
how to handle bash * matching when there are no matches?
The following bash snippet works great when there are actually *.txt files in the directory.
for txt in *.txt
do
echo "loading data from $txt"
done
When there aren't, the literal *.txt falls into…
kfmfe04
- 785
- 1
- 7
- 20
9
votes
1 answer
Does a wildcard inside double-quotes glob?
On a "standard BASH" does a wildcard inside double-quotes glob? For example:
$ touch abc
$ ls "*abc*"
would that, or wouldn't that work on bash?
I was told Ubuntu shipped with a bash variant that doesn't conform to POSIX or BASH. Is that true?
Matt
- 727
- 1
- 9
- 17
7
votes
1 answer
Bash partial glob expansion
I have a question similar to this one, but different: I want bash to use a glob expansion in auto-completion, if possible. For example, I would like
$ ls *2.
To give me:
$ ls mydoc2.
mydoc2.pdf mydoc2.tex mydoc2.txt
I face this situation…
Ryo
- 359
- 2
- 5
7
votes
5 answers
How to use _one_ shell globbing expression to list all files (of course hidden files too!)?
Ok, this question targets Unix/Linux shells!
I want a shell globbing (aka wildcard) pattern or GLOBIGNORE list that matches all files, including hidden files, in the current directory non-recursively (maxdepth == 1). So far, I have to perform two…
math
- 2,507
- 7
- 27
- 43
6
votes
2 answers
How to exclude a file from a command with ZSH?
Given this directory content :
one.file
two.file
three.file
in bash, when I enter
rm *.file !(two)
only one.file and three.file are deleted. How can I do this in ZSH?
yPhil
- 2,043
- 1
- 16
- 19
6
votes
1 answer
Exclude directories in ZSH glob
With zsh, you can use **/* as a short alternative to using find. Is there any way to restrict that to regular files, that is an equivalent to the -type f option?
Erik
- 691
- 2
- 7
- 23
6
votes
2 answers
How can I expand both a variable name and a wildcard in a file name?
I have a bash script where $DIR is a directory name that may contain spaces.
This:
rm "$DIR/*.MOV"
gives the error "No such file or directory". There is no file literally named "*.MOV"; I want the * to expand into multiple arguments - one per…
Nathan Long
- 24,089
- 33
- 97
- 137
5
votes
2 answers
"ls" or regex is case insensitive?
In bash, I tried
ls [a-z]*
and expected to list all the files with filename starts with small case alphabet. But why the files with name starts with big case alphabet are also shown?
>ls [a-z]*
D e
>
In case needed, the bash version:
bash…
zhanwu
- 923
- 3
- 15
- 20
5
votes
2 answers
How do I make bash's glob character classes case-sensitive?
I had created some files like knob_A.png and knob_a.png and my teammate on Windows said this caused problems with her app. I decided to call it knob_W.png instead of knob_a.png. Then I did an rsync up to our shared server. In order to clean…
Mutant Bob
- 352
- 4
- 14