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