From: Alexandru Diaconu on 14 May 2010 07:22 With globstar turned on, I can either list (in a recursive manner) every directory that follows the current working directory or, every directory and file that follows CWD. My question is: is there a glob pattern that eliminates directories from the listing before it is printed to stdout? The problem is that there isn't a trailing slash in the names of the directories so that one could easily exclude them with the aid of extglobs.
From: Stephane CHAZELAS on 14 May 2010 08:12 2010-05-14, 04:22(-07), Alexandru Diaconu: > With globstar turned on, I can either list (in a recursive manner) > every directory that follows the current working directory or, every > directory and file that follows CWD. My question is: is there a glob > pattern that eliminates directories from the listing before it is > printed to stdout? The problem is that there isn't a trailing slash in > the names of the directories so that one could easily exclude them > with the aid of extglobs. With zsh: **/*(.) is: only regular files **/*(^/) is: non directories **/*(-.) is: regular files and symlinks to regular files. ***/*(^/) descends into symlinks to directories. Note that it's zsh that introduced **. ksh93 followed a few years later, but did it in a more limited way (and slightly different), bash followed later and mostly copied ksh93. I don't think bash or ksh93 have equivalents to zsh's globbing qualifiers, so you'd have to do the exclusion by hand: set -- **/* for i do [ -d "$i" ] || set -- "$@" "$i" shift done ls -ld -- "$@" Or just forget about **: find . ! -type d -exec ls -ld {} + -- Stéphane
From: Alexandru Diaconu on 14 May 2010 10:58 Thanks Stéphane for taking a more general approach of describing how this feature is implemented across different shells. I completely forgot to mention that I was trying to do this in bash. It was my impression that the 'globstar' shopt is a bash specific feature. If my understanding is correct, it seems that there isn't a clean way to do this using only bash syntax. So, I guess I'm gonna stick to using 'find': 'find . -type f -print' seems a lot simpler that your alternative. Am I missing something here?
From: Janis Papanagnou on 15 May 2010 18:11 Alexandru Diaconu wrote: > Thanks St�phane for taking a more general approach of describing > how this feature is implemented across different shells. > > I completely forgot to mention that I was trying to do this in bash. > It was my impression that the 'globstar' shopt is a bash specific > feature. > > If my understanding is correct, it seems that there isn't a clean way > to do this using only bash syntax. So, I guess I'm gonna stick to > using 'find': > > 'find . -type f -print' seems a lot simpler that your alternative. Am > I missing > something here? Using find(1) (or any similar tool) seems more appropriate than using shell globbing for your purposes. Globbing does pattern matching on names of various file entities, while find(1) will consider the file attributes (in addition to basic shell globbing on files names). Janis
|
Pages: 1 Prev: Auto escaping ? Next: using bash pathname expansion for string matching |