Well this is an old thread.
To expand on the previous post, yes, the dotfiles aren't being shown since it's the shell doing the expanding, and shell globbing ignores hidden files by default.
In fact because the shell is the program doing all the work, it's not even necessary to use
ls at all (unless you want long-form information). A simple
echo will do just as well.
As shown before, the way to glob-match directories is to add a slash after the glob pattern.
(I personally like using
printf instead of echo, to allow printing each file on a separate line. The remaining examples will use that.)
Bash from version 4 also has a recursive globbing pattern.
Note though that I've personally had problems with
** locking up the shell when using it certain directories. I still haven't figured out exactly what causes it, but I suspect it has something to do with recursive symlinks.
You can also recursively glob for files by adding additional globbing patterns after it.
Code:
printf '%s\n' **/*.txt #lists all text files in the current directory and below
To print hidden files, simply enable the
dotglob option first. To exclude certain entries from the list, you can add patterns that match them to the GLOBIGNORE shell variable (colon-separated), or with extended globbing patterns.
Code:
shopt -s dotglob
GLOBIGNORE=tmp/*:temp/* #ignores the tmp/temp directories and all sub-entries
shopt -s extglob #not enabled by default
printf '%s\n' **/!(*.txt) #prints everything except text files.
See here for more on shell globbing.
globbing
extended globbing
In any case, for more complex matching,
find is definitely the tool of choice. Be sure to use the
-print0 null-terminator option if you need the list to be read by other commands.
http://mywiki.wooledge.org/UsingFind
http://www.grymoire.com/Unix/Find.html