LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-17-2005, 12:07 PM   #1
shukla_chanchal
Member
 
Registered: Oct 2005
Location: banglore(india)
Posts: 62

Rep: Reputation: 15
easy one


how can i count the number of directory in a directory

ls -d is not working
tell me if anyone of u know
thanks
 
Old 11-17-2005, 12:45 PM   #2
camorri
LQ 5k Club
 
Registered: Nov 2002
Location: Somewhere inside 9.9 million sq. km. Canada
Distribution: Slackware 15.0, current, slackware-arm-currnet
Posts: 6,233

Rep: Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860
Try the 'tree' command. You may need to install it first, it is not installed by default on all distros.

It will count directories and files.
 
Old 11-17-2005, 02:44 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Re: easy one

Quote:
Originally posted by shukla_chanchal
how can i count the number of directory in a directory

ls -d is not working
tell me if anyone of u know
thanks
As always in Linux/Unix there's more than one way ...

ls -l | grep "^d" |wc -l
echo "$((`find -type d -maxdepth 1|wc -l` - 1))"

Cheers,
Tink

Last edited by Tinkster; 11-17-2005 at 02:47 PM.
 
Old 11-18-2005, 07:10 AM   #4
alienDog
Member
 
Registered: Apr 2004
Location: Europe
Distribution: Debian, Slackware
Posts: 505

Rep: Reputation: 48
ls -1d [dirname]/* | wc -l

this won't recurse though...
 
Old 11-18-2005, 01:55 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally posted by alienDog
ls -1d [dirname]/* | wc -l

this won't recurse though...
Plus it will count any ordinary file as well ...


Cheers,
Tink
 
Old 11-19-2005, 08:43 AM   #6
alienDog
Member
 
Registered: Apr 2004
Location: Europe
Distribution: Debian, Slackware
Posts: 505

Rep: Reputation: 48
Right you are, so it seems. I should have tested it first
 
Old 11-19-2005, 10:16 AM   #7
shukla_chanchal
Member
 
Registered: Oct 2005
Location: banglore(india)
Posts: 62

Original Poster
Rep: Reputation: 15
thanks u people have given me exat answer
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
easy connect not easy in suse greg collins Linux - Newbie 11 03-30-2006 07:31 PM
Easy urpmi ,no easy send mail. akihandyman Linux - General 2 12-27-2004 02:15 PM
Linux4RegularGuys - EASY FTP setup using vsftpd - READ THIS FOR EASY HELP DropHit Linux - Networking 4 11-25-2004 02:44 PM
Easy for most ... Please help.... kaz4u2dig Linux - Newbie 1 10-18-2004 09:46 PM
Here's an easy one... jhotchkiss Linux - Software 5 09-23-2003 11:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration