8/17 How can one match wildcards '*' with files that start with a '.' in
bash and tcsh?
\_ .[^.]* works for most cases, but will not match "..foo"
\_ ls -A1 | grep '^\.'
\_ ls * .*
\_ i personally prefer .??* .
\_ ls `find . -type f -name .\*`
\_ ls `find . -type f -name .\*`, although it's not using the wildcard
facility in the shells.
\_ this will traverse down the directory tree. this behavior
would be different from what the others do and may or may not
be desirable.
\_ Use this then: echo `find . -type f -name .\* -maxdepth 1`
\_ At this point, what do you gain by using find? It would
be better if you were tall enough to use xarg or even
-exec. There would still be no point in using find though.
\_ Example without using "find" please?
\_ from above, .* or .??*
\_ ".*" will always exclude the parent directory
because ......? And ".??*" will still work if
there's a file named ".f" because ......?
\_ % echo .*
. [deleted] .. [deleted]
% echo .?*
[deleted] .. [deleted]
Try it yourself. Whether you want . depends
on what you'd want to do with the results,
I'd guess.
\_ BTW, ls `find [...]` should choke on file
names with a space. Probably other things too.
\_ Yes it does, but as in my -maxdepth example
above I already switched to echo `find ...`.
\_ echo only works because it doesn't use
the result of the find to touch the
file system. your examply `find [...]`
will fail any time someone tries to do
that, so it's not a complete solution,
as well as being one wasteful of system
resources. again, i urge you to learn
either xargs or -exec. preferably xargs,
but like partha likes to say, you have
to be this tall to use xargs.
\_ Your example ".*" will fail even when
no one tries to "touch the file
system." (By "touch the file system"
I suppose you meant accessing the
files afterwards using the match
result, since expanding filename
wildcards already requires touching
the file system.
\_ % mkdir ".try this"
% ls -d .*
./ ../ .try this/
you have access to a csh? show me
where it fails.
\_ Again, . and .. are not files.
\_ again,
% od .
% od ..
\_ % cd /
% which od
/usr/local/bin/od
% od .
od: .: Is a directory
0000000
% od ..
od: ..: Is a directory
0000000
%
And you point?
\_ /usr/bin/od
obtw,
% ls /usr/local/bin/od
ls: /usr/local/bin/od:
No such file or directory
in any case, i have to
leave for dinner.
\_ Indeed.
% touch "try this"
% ls
try this
% ls `find .`
ls: ./try: No such file or directory
ls: this: No such file or directory
.:
try this
Like I said, I wish you were tall enough
to use xargs or -exec.
\_ You being tall enough to use xargs or
-exec didn't help the fact that your
example doesn't even work in any
directory. So what's the point.
\_ which example? i merely copied from
solutions above. .* does work for
all files, including . and .. .
.?* will exclude ., which is perhaps
nice.
\_ Excuse me? . and .. are not files,
are they?
\_ sure they're not files.
\_ obtw,
% od .
% od ..
\_ also xargs, but you have to be this tall to use it.
\_ this task is trivial if you use 'set noglob'. |