Annoying globbing
|
| Author | Content | ||
|---|---|---|---|
| Sander_Marechal Oct 09, 2008 5:47 PM EST |
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 6:22 PM EST |
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 4:32 AM EST |
But that fails to match dotfiles with less than three characters. | ||
| gus3 Oct 10, 2008 4:40 AM EST |
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 12:11 PM EST |
> But that fails to match dotfiles with less than three characters. Did I make a typo? In that case, use .? |
||
| jdixon Oct 10, 2008 12:20 PM EST |
> Did I make a typo? In that case, use .? But .? should match .. |
||
| jezuch Oct 10, 2008 2:32 PM EST |
What if I drop a file called ".?ó??"? :) I usually use this one: .[^.]* |
||
| jezuch Oct 10, 2008 2:34 PM EST |
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 5:55 PM EST |
Ha! I just found the 'dotglob' option. run "shopt -s dotglob" and now * will match dotfiles but not . and .. | ||
| herzeleid Oct 10, 2008 7:51 PM EST |
> 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 11:08 PM EST |
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 11:32 PM EST |
> 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 3:32 AM EST |
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!

