Find number of files in folder and sub folders?
May be something like
find . -type f | wc -l
would do the trick. Try the command from the parent folder.
find . -name <pattern> -type ffinds all files in
.and subfolders. The result (a list of files found) is passed (
wc -lwhich counts the number of lines.
-name <pattern>only looks for certain files.
@arrange: even faster: `find . -type f -printf . | wc -c` - I adopt the print for my solution instead of my -exec echo .
Be aware that this also counts hidden files starting with a dot. I consider this a feature rather than a bug, but it is good to know.
To count files (even files without an extension) at the root of the current directory, use:
ls -l | grep ^- | wc -l
To count files (even files without an extension) recursively from the root of the current directory, use:
ls -lR | grep ^- | wc -l
The fastest and easiest way, is to use
tree. Its speed is limited by your output terminal, so if you pipe the result to
tail -1, you'll get immediate result. You can also control to what directory level you like the results, using the
-Loption. For colorized output, use
-C. For example:
$ tree share/some/directory/ | tail -1 558 directories, 853 files $ tree -L 2 share/some/directory/ | tail -1 120 directories, 3 files
If it's not already there, you can get it here.
find -type f -printf . | wc -c
Don't count the output lines of find, because filenames, containing 99 newlines, will count as 100 files.
You can use
find . | wc -l
find .will list all files and folders and theire contents starting in your current folder.
wc -lcounts the results of find
This solution counts also the folders, I gave the mark cause it matched my occasion that I didnt want to count them in :)
find seems to be quicker than tree so I used below to count files in each directory of the current working directory (ignoring files in CWD) with allowing directories to have spaces:
ls -d */ | while read dir_line do echo -n "$dir_line :" find "$dir_line" -type f | wc -l done