bug-fileutils
[Top][All Lists]
Advanced

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

Re: bug in ls - use of * with dot files and -a


From: Bob Proulx
Subject: Re: bug in ls - use of * with dot files and -a
Date: Tue, 22 Jan 2002 02:37:06 -0700

> g'day,

G'day Dan!

>       just reporting what appears to be a small bug in ls.
> It seems that when I use the * wildcard at the
> beginning of a string with ls, it doesn't list dot
> files, even when used with the -a option.

That is the way it is supposed to work.

The command shell expands the '*' before ever handing it to a command.
This is regardless of it being ls as it could be any command on the
command line.  The '*' is called the glob character because it matches
a glob of character.  This process is called file name globbing.  This
is documented in your shell manual.  Bash documents this well.  In the
bash info pages look for the section titled ``Filename Expansion''.

A '*' is a shell pattern and is replaced by a list of files that match
that pattern.  Filenames that start with a '.' do not match that
pattern.  Neither does it match a '?'.  The dot character must be
explicitly matched when it occurs at the start of the filename.

You should test what input is being given to commands by the shell
with the "echo" command.  Try these patterns as starting examples.
Try this in your home directory where there are usually rich examples
of dot files.

  echo *
  echo .*
  echo .* *
  echo .?*
  echo .??*

As you will see from those examples the ls command is only listing out
the files that were presented to it by the shell.  Which answers why
the dot files were not listed.  In fact, what is ls doing that you
can't do yourself?  Very little in this particular case.  You might as
well use 'echo' for listing and then you can use the 'fmt' command to
word wrap to your screen.  You can also use 'tr' and 'grep' to finish
the job.  Suddeny using ls for this seems more convenient.  Especially
when coupled with the -l option!

  echo * | fmt
  echo .* | fmt
  echo .* * | fmt
  echo .* * | tr " " "\012" | grep profile

But then how does one list out dot files?  There are several ways that
are typically used.  Here are a variety of examples that should spark
ideas for you.  Try them out and compare and contrast their
differences.

  ls -a | grep profile
  ls -d .*
  ls -d .??*
  ls -d .[^.]*
  ls -d .[!.]*

Some are more convenient than others.  But dot files are -meant- to be
hidden files.  Therefore it is reasonable that you will need to do a
little more work to unhide them.

You should also read over the answers to other questions in this FAQ
as this is a very similar theme.  Read the documentation on your
shell.  For GNU systems 'info bash' will launch the info system on the
bash documentation.  I also recommend reading one of the many fine
shell programming books available from the bookstore.

You may want to consult the FAQ.

  http://www.gnu.org/software/fileutils/doc/faq/core-utils-faq.html

Hope that helps.
Bob



reply via email to

[Prev in Thread] Current Thread [Next in Thread]