Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 01-19-2012, 09:46 AM   #1
LQ Newbie
Registered: Oct 2011
Posts: 20

Rep: Reputation: Disabled
Post directory and subdirectories

im trying to write a script that finds the number of sub directories in a directory specified
Old 01-19-2012, 09:48 AM   #2
LQ Newbie
Registered: Apr 2011
Posts: 12

Rep: Reputation: 5
find <specified directory> -type d|wc -l

I hope that helps you.
1 members found this post helpful.
Old 01-19-2012, 09:52 AM   #3
Registered: Nov 2010
Location: Minneapolis, MN
Distribution: Ubuntu, Red Hat, Mint
Posts: 172

Rep: Reputation: 56
find /path/to/directory/* -type d | wc -l
This will exclude the directory itself, if you also want to count that remove the "*"
It will also not follow symlinks, if you want it to do that, add the -L option after "find"
1 members found this post helpful.


bash, bash scripting, linux command, unix

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
How to delete all images from a directory/subdirectories SentralOrigin Linux - General 2 04-16-2009 03:54 AM
Copying a Directory into Another Directory with Subdirectories oadvantage Linux - Newbie 4 03-06-2006 06:27 PM
copy 3 files to a directory and all subdirectories? snip128 Linux - Newbie 9 08-12-2005 10:18 PM
why can't the /bin directory contain subdirectories? learnfast Linux - Newbie 2 03-09-2005 12:31 PM
read directory and subdirectories skora Programming 3 10-27-2003 11:22 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:54 PM.

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