Questions tagged [globbing]

Globbing is a way to match sets of paths without explicitly specifying paths. For example, the * glob would match all paths in a directory.

55 questions
40
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
  • 518
  • 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,412
  • 10
  • 42
  • 43
27
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,633
  • 8
  • 31
  • 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
  • 10,107
  • 7
  • 29
  • 33
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
  • 6
  • 17
13
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
  • 865
  • 1
  • 9
  • 21
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,537
  • 7
  • 34
  • 50
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
  • 767
  • 1
  • 11
  • 18
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
  • 379
  • 2
  • 5
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,451
  • 1
  • 19
  • 19
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
  • 748
  • 2
  • 9
  • 23
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,633
  • 8
  • 31
  • 43
6
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
  • 677
  • 4
  • 12
  • 28
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
  • 26,015
  • 36
  • 102
  • 139
5
votes
4 answers

How to list files based on matching only part of their filename?

I have many files in a folder for example Kiran.txt Kiran1.txt Kiran221.txt Kiran144.txt Time.csv Timer.csv Timer2.csv Timer444.csv Timer266.csv Account.sh Account3.sh Account3333.sh Account3333.sh Account333333.sh From this directory, I want to…
Lavanya
  • 155
  • 1
  • 3
  • 5
1
2 3 4