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!
Notices
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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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))
That's the only way I would know to do it either, there must be a way of counting just files though. It'd be nice to get an output like: 13 files
4 directories
2 symbolic links
You could write a little script to do that cnm and post it up for us! :P
If they have the same extension you can count using:
ls *.txt | wc
You can use the diffcommand to compare two directories if you just want to ensure that it copied successfully.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.