Re: Bash globbing files only?

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

 



Daniel Qarras wrote:
Hi!

Yep, that would work, but I guess my question was a bit poorly
formulated. I am writing a bash script that has:

dirs=[^.]*/

and I'd like to have "files=..." without using find or other
external
commands if at all possible.

Thanks.

Of course the best way is with the find command, being

find / -type f

Any reason why you'd rather use ls instead of find?

I want just the files from the current directory, not from any subdir.
And I'd prefer some bash globbing if possible for performance/elegancy
reasons :)

Find has more options than you want to know about:

find . -maxdepth 1 -type f -name 'pattern'

Don't forget to quote 'pattern' so the shell won't expand it.

Or you could do something like:

ls -ld pattern |sed -e '/^d/d' -e 's/.* //'
(remove the lines starting with d and all the stuff before the name).

The only way to do it without an external command would be to expand the list in the shell and cycle though the list eliminating the directories with a [ -d $VAR ] test. See 'man test' for the options, but it really is a shell built-in.

--
  Les Mikesell
  lesmikesell@xxxxxxxxx

[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