Re: Bash globbing files only?

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

 



On Mon, 2007-01-29 at 12:14 -0800, Evan Klitzke wrote:
> On Sun, 2007-01-28 at 12:12 -0800, Daniel Qarras wrote:
> > Hi all,
> > 
> > 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.
> 
> Daniel,
> 
> My knowledge of bash is very limited, but I believe that the -d
> conditional checks if a file is a directory. So you could define a
> function something like this (the syntax is probably all wrong, but
> hopefully it is decipherable):
> 
> for file in `ls -1`; do
>     if ![ -d file]; then
>         printf "$file\n"
>     fi
> end
> 
> Name the function something like "lsfiles" and you're good to go.

Uh, how about "find . -maxdepth 1 -type f -print" to list the files and
"find . -maxdepth 1 -type d -print" for directories?  Take out the
"-maxdepth 1" and it'll walk the directory tree.

Nah, too prosaic!

----------------------------------------------------------------------
- Rick Stevens, Senior Systems Engineer     rstevens@xxxxxxxxxxxxxxx -
- VitalStream, Inc.                       http://www.vitalstream.com -
-                                                                    -
-     Make it idiot proof and someone will make a better idiot.      -
----------------------------------------------------------------------

[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