LinuxQuestions.org
Review your favorite Linux distribution.
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, 01: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, 01:45 PM   #2
camorri
LQ Guru
 
Registered: Nov 2002
Location: Somewhere inside 9.9 million sq. km. Canada
Distribution: Slackware 14.1, 14.2
Posts: 5,172

Rep: Reputation: 526Reputation: 526Reputation: 526Reputation: 526Reputation: 526Reputation: 526
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, 03:44 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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 03:47 PM.
 
Old 11-18-2005, 08:10 AM   #4
alienDog
Member
 
Registered: Apr 2004
Location: Europe
Distribution: Debian, Slackware
Posts: 505

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

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

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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, 09:43 AM   #6
alienDog
Member
 
Registered: Apr 2004
Location: Europe
Distribution: Debian, Slackware
Posts: 505

Rep: Reputation: 46
Right you are, so it seems. I should have tested it first
 
Old 11-19-2005, 11: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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 08:31 PM
Easy urpmi ,no easy send mail. akihandyman Linux - General 2 12-27-2004 03:15 PM
Linux4RegularGuys - EASY FTP setup using vsftpd - READ THIS FOR EASY HELP DropHit Linux - Networking 4 11-25-2004 03:44 PM
Easy for most ... Please help.... kaz4u2dig Linux - Newbie 1 10-18-2004 10:46 PM
Here's an easy one... jhotchkiss Linux - Software 5 09-23-2003 12:53 PM

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

All times are GMT -5. The time now is 07:24 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration