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]
59 questions
41
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
- 528
28
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,693
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,662
23
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
- 10,557
20
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
- 1,025
14
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
- 430
13
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,715
10
votes
2 answers
Windows Dir Command Not Behaving as Expected
In a directory, I have 3 files, all with the incorrect file extension jpgJPG.
When I type dir *.j I get no results, as expected.
When I type dir *.jp I get no results, as expected.
But when I type dir *.jpg it lists the 3 files, even though the…
mbmast
- 441
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
- 787
9
votes
2 answers
ZSH: glob with prefix
Is it possible to add a 'prefix' to the shell glob expansion?
My use case is the following, I have a program which requires repeating the option flag to pass multiple files as input:
$ ls
foo.txt bar.txt baz.txt
$ ./some-script.sh -a foo.txt -a…
gregseth
- 747
8
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
- 389
8
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,651
7
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?
Nova
- 780
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,693
7
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
- 27,435