On Thursday 12 December 2002 09:23 am, Pablo Manalastas wrote:
> On Thu, 12 Dec 2002, digest_ wrote:
> > how do you list the directories in linux using ls?
> > `ls -d` returns '.'

i thought ls -d would be a great thing to remember (there are too
many options, and only a small number of slots in my brain to hold
them, so i'd have to kick some other option out of its slot ;).  but 
like you i noticed that it only gives me the current directory.  on
my box it gives "./"

> ls -F | grep '/'

that works well.  i also often do:  
 
ls -l | grep ^d

if i want a long listing.

what do people do if they want to cut directory names out and some
directory names have spaces in them?  often i want to traverse the 
directories with a shell script, but using ls -l | grep ^d | cut -f 9 -d " "
doesn't work if there are spaces in the directory name.  using the
ls -F | grep "/" would work too, but in bash scripts, the parts of
the directory name (e.g., "Program" and "Files" in "Program Files")
will get separated and i can't cd into "Program" or "Files" :).

i guess my question boils down to:

given a list of directories from some combination of ls and grep,
how do i step through the list?, e.g., i often do:

for dir in `ls`
do
   if [ -d $dir ]
   then
      cd $dir
      <do something in $dir>
   fi
done

but if i have a directory named "aa bb" (note the space), then it's
not processed because i can't cd into "aa".  it sees it as "aa", not
"aa bb".

i saw a trick to do this once, long ago.  it had to do with putting
double quotes somewhere strategic, but i've forgotten the trick.

tiger

-- 
Gerald Timothy Quimpo  tiger*quimpo*org gquimpo*sni-inc.com tiger*sni*ph
Public Key: "gpg --keyserver pgp.mit.edu --recv-keys 672F4C78"
                   Veritas liberabit vos.
                   Doveryai no proveryai.
_
Philippine Linux Users Group. Web site and archives at http://plug.linux.org.ph
To leave: send "unsubscribe" in the body to [EMAIL PROTECTED]

Fully Searchable Archives With Friendly Web Interface at http://marc.free.net.ph

To subscribe to the Linux Newbies' List: send "subscribe" in the body to 
[EMAIL PROTECTED]

Reply via email to