Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with script

Status
Not open for further replies.

yodadbl07

Technical User
Apr 26, 2006
4
US
I would like to know how to list directories only without a / at the end. I would like to only see them in my current dir.

for example

ls - d */ gives

dir1/ dir2/ dir3/ dir4/

but is there a way to get only

dir1 dir2 dir3


I need to use it in this foreach loop:

Code:
foreach x ( ` ls -d */ ` )
  
     cd $x
  
     set subdir = ` ls -F | grep -c '/$' `
  
     @ subfiles = ` ls -F | wc -l ` - ` ls -F | grep -c '/$' `
  
     echo " There are $subdir directories and $subfiles files in your $x directory. "
     echo "  "
  end


the only problem is that not all the sub directories have a another dir inside them so when it gets to a dir that has no subdir it says that the dir "dirname/" does not exist. can anyone help.
thanks
 
man test
e.g.: test -d dirname || echo "dirname isn't a directory"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 

Try:

find . -type d

man find [noevil]





----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
man df
man sendmail

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
ls -d * | sed 's/\///g' ?

"If you always do what you've always done, you will always be where you've always been."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top