Bash globbing files only?
Cameron Simpson
cs at zip.com.au
Tue Jan 30 00:56:46 UTC 2007
On 29Jan2007 18:58, Jacques B. <jjrboucher at gmail.com> wrote:
| >Got an alias for "ls"? Try:
| > unalias ls
| > ls -d */
| >
| >The -d says don't treat directories specially (normally ls lists
| >directory _contents_ if a directory is named).
|
| I do have an alias for ls, but it's simply to add color. I did the
| unalias and get the same results. Now with the one you have listed
| here, I do get the directories. Even when I source my .bashrc back to
| get the alias back, it still works as expected. So the alias is not
| affecting my ls beyond adding color.
|
| Is the command $ls [^.]*/
| working as expected for you, listing only directories in your current
| directory?
Yep, in both zsh and bash. BTW, what is the "[^.]" supposed to achieve?
A plain "*" should act the same, I'd expect.
Try this:
set -x
ls [^.]*/
ls -d [^.]*/
ls -d */
It would be interesting to see what the differences are, if any.
You could whack a ">/dev/null" onto the end of the ls commands
so the "set -x" tracing is easy to see.
| I'm fairly comfortable with the basics of bash and some intermediate
| bash but I hadn't played with globbing much. In reading up on it I'm
| left with the impression that the command above would list all files
| not starting with a period ([^.]), then the wildcard * (so could be
| anything at all),
Yes, but plain "*" is supposed to not match things beginning with "."
anyway.
| followed by the / (which doesn't seem to do
| anything).
Yes it does - it forces a path traversal. You can do that with a
directory, but not a file (nothing to transverse "into").
| Even if it did work, would it not exclude any directory starting with
| a period?
Yes. I suspect it's a mistake from people trying to avoid "." and "..".
| But that aside, does it work (or not work) for anyone else?
|
| I have
| GNU bash, version 3.1.17(1)-release (i686-redhat-linux-gnu)
Me too.
--
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/
A lot of people don't know the difference between a violin and a viola, so
I'll tell you. A viola burns longer. - Victor Borge
More information about the fedora-list
mailing list