Linux - NewbieThis 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!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
A directory is a file but its not a regular file, so the question is not clear enough
If he does not want directory, then something awfull like this should do:
echo $(($(ls -l | grep -v ^d | wc -l)-1))
Use the 'tree' command. If its not present in the system by default, I recommend installing it.
It outputs a beautiful tree structure showing the files and the directories and finally printing number of files and directories in a folder.
how to find number of files,subfolders in a file using command
I have taken clue from previous post & come up with simplest way
Finding number of files in a folder
find . -type f | wc -l
this means output of find comand (which is only files no directories)is sent to wc which counts number of lines i.e number of files
Finding number of subfolders in a folder
(1)find . -type d | wc -l
This will give number of subfolders+1 because current folder also gets included.Note that the folders inside subfolders are also included in count.
(2)If you want to see only number of folders in current folder then
find . -maxdepth 1 -type d | wc -l
Here output is numberof subfolders+1
NOTE:folders inside subfolders not considered.
If this information helps you please thank me by pressing thumbs up button.Happy hacking.
Last edited by sumeet inani; 10-28-2009 at 08:53 AM.