Re: Bash globbing files only?

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

 



Daniel Qarras <dqarras@xxxxxxxxx> wrote:

with Bash one can list directories (excluding dot dirs) like this:
> > > > ls [^.]*/ > > > > How can I list files instead of directories with Bash? I thought > this
> > would be trivial but I can't find a solution anywhere.
> > I don't think that it can be done with bash, but if you don't mind
> switching to zsh -- another extended version of the Bourne shell --
> it does become trivial:
> > ~% ls *(.) # list only plain files
>     ~% ls *(/)  # list only directories
>     ~% ls *(*)  # list only executable files
Yes, I am painfully aware of the power of zsh  :)  But in this case I
need to do my script with bash and it seems that although globbing for
directories is trivial ( */ ) there is no similar pattern to match
files. Oh, well, I guess I'll need to waste some CPU cycles and launch
find everytime I need to know file names in the current directory.

Thanks.
How about:

ls -dF ./.[^.]*/ ./*/
./.gconf//   ./.gnome2//          ./.kde//  ./.vnc//
./.gconfd//  ./.gnome2_private//  ./mail//

The extra trailing slash is a little untidy but this shouldn't be too hard to deal with in a shell script. Without the globbing the directory looks like:

ls -aF
./ .gnome2/ .tcshrc .xauthipFozN .xauthPzlpUy ../ .gnome2_private/ tuneSkge.sh* .xauthIS8EHj .xauthqjlydy .addressbook install.log .vnc/ .xauthk767SX .xauthS6Fe7J .addressbook.lu install.log.syslog .xauth3cMVlS .xauthKGKdHN .xauthVVWsxU anaconda-ks.cfg .kde/ .xauth63RXVT .xauthKTeKNJ .xauthxDbAPA .bash_history .lesshst .xauth94YA7P .xauthM83ZuG .xauthydqF9q .bash_logout local.mod .xautha7i7Cq .xauthmNPIZ6 .xauthYh5g1e .bash_profile local.te .xauthAMVrYt .xauthmoSEQs .xauthYVZ3d9 .bashrc mail/ .xauthBPKmdK .xauthnGzy76 .xauthz1gsvS .cshrc .pinerc .xauthdcbhGf .xauthoe3Llk .xauthZpCinp .gconf/ .recently-used.xbel .xauthf90gtu .xauthOhkaXl .xauthZpuD2k
.gconfd/         scsrun.log           .xauthGuEyXV  .xauthpGDShA


Cheers,
Dave

--
Politics, n. Strife of interests masquerading as a contest of principles.
-- Ambrose Bierce


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux