Re: Bash globbing files only?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 29Jan2007 18:58, Jacques B. <jjrboucher@xxxxxxxxx> 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@xxxxxxxxxx> 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

[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux