Subdirectory listing

Jonathan I. Kamens jik at athena.mit.edu
Wed May 24 05:16:06 AEST 1989


\begin{Hugeflame}

  OK, folks, once again it's time to review briefly what newsgroup
we're in right now, and what other newsgroups are available under the
comp.unix heirarchy.

  This is COMP.UNIX.WIZARDS.  The word "wizards" at the end is
supposed to imply that the questions and discussions conducted herein
require some GREATER THAN MINIMAL level of KNOWLEDGE and EXPERIENCE
with the Unix operating system, in whatever variety, on the part of
the people asking or discussing.

  It is my firmly held opinion that the following two topics DO NOT
qualify as questions worthy of the comp.unix.wizards newsgroup:

1. "How do I delete a filename that has strange characters in it?"

2. "How to I print out the complete path names of all subdirectories
   below a given directory?"

  Let me defend each of these assertions in turn.  The first concerns
deleting a strange filename.  It is my firmly held opinion that IF YOU
CAN'T FIGURE IT OUT, YOU SHOULDN'T BE POSTING IN COMP.UNIX.WIZARDS.
Go back to comp.unix.questions.  This question has been asked and
discussed in c.u.w WAY TOO MANY TIMES, and it's getting old.

  The second complaint I mentioned above has to do with a recent
question posted to c.u.w.  It read as follows: "I'm interested in
finding a unix command usage that will return the complete path names
of all subdirectories below a given directory..."  In other words, the
person asking the question wanted to be able to do "find <dir-name>
-type d -print."

  I object to this question for two reasons.  First, THIS IS NOT A
"WIZARD"-LEVEL QUESTION!  There is nothing whatsoever difficult about
it.  It should not present a problem to anybody who knows anything at
all about Unix.  And, if it does, then IT SHOULD HAVE BEEN POSTED IN
COMP.UNIX.QUESTIONS.

  The second complaint I have is that in response to this question, a
multitude of people posted messages TO THE NET answering it.  Many of
them were wrong or silly over-answers to a simple question, and ALL of
them should have been sent in private E-mail for the person who asked
the question to summarize.  Let's look at the answers to this question
which were posted (names omitted to protect the guilty):

1: I am sure there are lots of ways to do this. Here's a recursive C
   program to do it. It has its own limitations like maximum path
   length. I have a tree printing version of it too. It uses curses,
   terminfo etc.  The listing for syserr.h is also included.

   [incredible overkill C program to do what "find <dir> -type d
   -print" does already]

Surely you can't be serious!  Has this guy ever heard of find(1)?

2: find directoryname -type d -print

OK, this is correct answer number one.

3: find dirname -print

This is close, but it ignores the fact that the person who asked the
question only wanted to list directories, not files.

4: find /files/home/users -type d -print

This is correct answer number two.

5: Why not simply use find /foo -type d -print ?  Unless I
   misunderstand what you are trying to do, this does it....

This is correct answer number three.

6: [In response to earlier correct answers] Almost. Don't forget to
   pipe it to `sort', [sic -- punction outside of quotation marks?
   tsk, tsk :-)] as find doesn't.  And <name deleted> forgot that
   he asked for directorys [sic] only.

   One thing I recently discovered is that find takes multiple
   directorys [sic] before the options: find /here /there /everywhere
   -dothis -dothat ...

I guess we should call this a "correct answer," so this is correct
answer number four.  And I'll bet that all of us were enlightened to
find out that find can take multiple paths on which to operate.  I
guess that's what the man page means when it says that "find
pathname-list expression" is the usage, and a "pathname-list" is
"(i.e. one or more pathnames)."

7: [in response to the wonderful C program mentioned above] "Yes,
   there are lots of ways; using the already-written "find" command is
   far easier than writing your own program to do the same thing...."

Yes, this is true.  But gee, look, you haven't explained how to do it!
What a useful answer!  I'm afraid this one can't be classified as a
"correct answer."  Sorry, you don't win the prize....

8: .... Um... am I missing something or doesn't

	du -a .
   or

	du -a your_favorite_directory

   do all this stuff without the fuss and muss?  Is this really a
   "wizards" type question?

Yes, you apparently are missing something.  First of all, the guy who
asked the question only wanted directory names, not filenames, and "du
-a" lists filenames.  You would have been closer if you'd suggested
just "du" rather than "du -a."  Second, this has the unfortunate side
effect of printing the size of every directory in addition to its
path.  Did the person asking the question say he wanted to do this?
If so, then I missed it.

9: Give this script a spin around the block

   [shell script that (get a load of this!) takes each directory
   specified on the command line and runs "find <dir name> -type d
   -exec ls -d {} \;" on it]

Gee, it looks like you know about the find(1) command, but you're
completely confused.... has it occurred to you that find takes
multiple paths on the command line, or that the user asked for a
recursive listing and your script will not list recursively?  I
thought not.

  The net (pun intended) result of all this is eight responses posted
in comp.unix.wizards to a question that should never have gone into
c.u.w. in the first place.  Besides that, only four of the eight
messages provided the "correct" solution to the problem.

  CAN YOU SAY, "MAJOR TEN-TON LOSE?"  I thought so.

\end{Hugeflame}

  OK, let me reiterate the points I've tried to make in this posting:

1. Please, please, don't post a question to comp.unix.wizards unless
   you really are convinced that it's going to take the combined brain
   power of multiple "wizards" to answer your question.
   Comp.unix.questions should be your first resort in questions about
   Unix unless you are 100%, cross-your-heart-and-hope-to-day sure
   that your question is not a simple one.

2. When someone asks a question on the net and it is likely that
   several people will respond, ANSWER THE QUESTION IN E-MAIL!  DON'T
   post an answer to the net.

3. If you AREN'T a wizard, DON'T answer questions in
   comp.unix.wizards!  I hate to be blunt, but it's just plain STUPID
   (IMHO) to post a C program and a shell script to do what find(1) is
   designed to do!

  OK, I'm off my soapbox.  I feel much better now.

Jonathan Kamens			              USnail:
MIT Project Athena				410 Memorial Drive, No. 223F
jik at Athena.MIT.EDU				Cambridge, MA 02139-4318
Office: 617-253-4261			      Home: 617-225-8218



More information about the Comp.unix.wizards mailing list