Skip to content

List number of files in each directory in Linux

find . -type d -print0 | while read -d '' -r dir; do
    files=("$dir"/*)
    printf "%5d files present in %s\n" "${#files[@]}" "$dir"
done

Sample

	3 files present in .
    1 files present in ./roles
    1 files present in ./roles/copy-build-artifacts
    1 files present in ./roles/copy-build-artifacts/tasks
    3 files present in ./inventories
    1 files present in ./inventories/prod
    1 files present in ./inventories/dev
    1 files present in ./inventories/qa

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.