Annoying globbing

Story: Bash Extended GlobbingTotal Replies: 12
Author Content
Sander_Marechal

Oct 09, 2008
4:47 PM CST
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.
herzeleid

Oct 09, 2008
5:22 PM CST
I always just say * .??* to mean all files.

Of course the ?? after the dot is to keep it from matching . and ..
Sander_Marechal

Oct 10, 2008
3:32 AM CST
But that fails to match dotfiles with less than three characters.
gus3

Oct 10, 2008
3:40 AM CST
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.
herzeleid

Oct 10, 2008
11:11 AM CST
> But that fails to match dotfiles with less than three characters.

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



jdixon

Oct 10, 2008
11:20 AM CST
> Did I make a typo? In that case, use .?

But .? should match ..
jezuch

Oct 10, 2008
1:32 PM CST
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: .[^.]*
jezuch

Oct 10, 2008
1:34 PM CST
Argh. There are supposed to be funny characters in my example filename, not question marks. Who wrote this forum software?? ;P
Sander_Marechal

Oct 10, 2008
4:55 PM CST
Ha! I just found the 'dotglob' option. run "shopt -s dotglob" and now * will match dotfiles but not . and ..
herzeleid

Oct 10, 2008
6:51 PM CST
> 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.
gus3

Oct 10, 2008
10:08 PM CST
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.
herzeleid

Oct 10, 2008
10:32 PM CST
> 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 ..

jezuch

Oct 11, 2008
2:32 AM CST
Quoting:Yep, that's why we say .?? to avoid matching . or ..


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

Posting in this forum is limited to members of the group: [ForumMods, SITEADMINS, MEMBERS.]

Becoming a member of LXer is easy and free. Join Us!