Posted By

noah on 01/03/08


count FileSystem easy

Versions (?)

Count the number of files in a directory

 / Published in: Bash


How many files are in the current working directory? This is recursive, so the count includes subdirectories and files contained in subdirectories. To get a non-recursive count of just the files/directories in the current working directory, use ls -1 in place of find .

  1. find . | wc -l

Report this snippet  


RSS Icon Subscribe to comments
Posted By: amosshapira on January 13, 2008

It will count also directories, including "." and "..". The "ls" solution can take too long on huge directories because it will unnecessarily read in the entire list of file names and sort them. To avoid the "sort" youge can add "-U" The "ls" solution will skip files beginning with "." unless adding "-A".

I have perl script at work which does this with all sorts of bells and whistles, but just to demonstrate a point I'll upload a simple version I wrote right now (no access to the full script right now).

You need to login to post a comment.