Message Board -  Archive

[ Login ] [ Create Account ]
[ Board List ] [ View Board ] [ Post Reply ]
  Author  Subject: Re: ls question

Posted on 07-20-2004 01:46 a.m. ET  reply

Original Poster: Mark Krentel

> what is the equivalent command of the DOS 'c:dir /d'? Sounds
> simple enough, doesn't it? I just want to list directory entries
> that are themselves directories

Well, I don't speak DOS (and I don't do Windows :-). "man ls" will
give you the possible options. But if what you want is to restrict
ls to just subdirectories, then there isn't an option for this (or
more precisely, GNU/FSF hasn't written one yet :-).

But you can use the standard Unix/Linux technique of combining
commands. For example, in the long form:

ls -l | grep '^d'

is pretty much what you want. If this is something you do frequently,
then define an alias or function for it.

> What is the syntax for listing all files in my current working
> directory and all subdirectories underneath my current one that fit
> a particular pattern?

"ls -R" recursively lists all subdirectories (which you could pipe
into grep as above). But really, "find" is the program you want.
find (see "man find") has options for just about anything you could
imagine: file name, type, size, modification time, owner, group,
permission, etc. For example:

find . -name 'art*.*'

would match file names art.doc, art2.cpp,, etc, in any
directory at or below the current one.

Actually, find combined with "xargs" does far more than merely listing
files. You can run another command for each file that matches the
pattern (see "man find" and "man xargs").


< Previous 1 Next >

Site Contents