Archive for February, 2007

Count the number of files in a directory and all sub directories in Bash (Unix or Linux)

Sunday, February 11th, 2007

Counting the numher of files in a directory is easy:
ls | wc -l
Taking the sub directories requires a little more, so I made a script:
#!/bin/sh
ls -a $@ | while read dir
do
find “$dir” | wc -l | tr “\n” “\t”
echo […]