Advanced

Bash Extended Globbing

Posted by Scott_Ruecker on · 13 comments
Linux Journal; By Mitch Frazier
Mail this story
Print this story

Wildcards in bash are referred to as pathname expansion. Pathname expansion is also sometimes referred to as globbing. Pathname expansion "expands" the "*", "?", and "[...]" syntaxes when you type them as part of a command, for example..

Full Story

  Nav
» Read more about: Story Type: News Story; Groups: Linux

» Get new stories by e-mail: nightly or as they are published

« Return to the newswire homepage

  Related stories
» More like this

Comments (13)

There's one thing that always annoyed me about globbing: How can I match *all* files in a directory? Not just regular files but hidden dotfiles as well, but obviously not the special . and .. directories.

It often happens that I want to move/copy all files from one directory to another but then it leave behind .htaccess files and the like.
I always just say * .??* to mean all files.

Of course the ?? after the dot is to keep it from matching . and ..
But that fails to match dotfiles with less than three characters.
I use ".[0-9A-Za-z]*" to match the hidden files and directories. In my $HOME, I have none with strange symbols after the first dot, so that pattern matches well enough for me.
> But that fails to match dotfiles with less than three characters.

Did I make a typo? In that case, use .?



> Did I make a typo? In that case, use .?

But .? should match ..
Quoting:I use ".[0-9A-Za-z]*" to match the hidden files and directories.


What if I drop a file called ".?ó??"? :) I usually use this one: .[^.]*
Argh. There are supposed to be funny characters in my example filename, not question marks. Who wrote this forum software?? ;P
Ha! I just found the 'dotglob' option. run "shopt -s dotglob" and now * will match dotfiles but not . and ..
> Ha! I just found the 'dotglob' option. run "shopt -s dotglob" and now * will match dotfiles but not . and ..

Very good to know - and it just goes to show you, no matter how long you stay in this game, there is always something new to learn.
Dot-question and dot-dot are dangerous, because they will take you up instead of down.

@jezuch:

The forum began mis-behaving after the blackout recovery.
> Dot-question and dot-dot are dangerous, because they will take you up instead of down.

Yep, that's why we say .?? to avoid matching . or ..

Quoting:Yep, that's why we say .?? to avoid matching . or ..


Or .a or .b or... ;)

Post a comment

A free account is needed to post. Write your comment here first: your text is kept in this browser while you sign up or log in, and is waiting for you when you come back.

Your message:
|||||
10
Markdown: **bold**, *italic*, [text](https://link), - lists, > quotes, $x^2$ for math. Formatting help

Sign up and post (it is free)  or  Log in and post