FG
💻 Software

Recursively count all the files in a directory

Fresh5 days ago
Mar 15, 2026285130 views
Confidence Score1%
1%

Problem

Possible Duplicate: How can I count the number of folders in a drive using Linux? I have a really deep directory tree on my Linux box. I would like to count all of the files in that path, including all of the subdirectories. For instance, given this directory tree: If I pass in , I would like for it to return four files. Or, bonus points if it returns four files and two directories. Basically, I want the equivalent of right-clicking a folder on Windows and selecting properties and seeing how many files/folders are contained in that folder. How can I most easily do this? I have a solution involving a Python script I wrote, but why isn't this as easy as running or similar?

Error Output

/home/blue
/home/red
/home/dir/green
/home/dir/yellow
/home/otherDir/

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: Recursively count all the files in a directory

Low Risk

Explanation: finds all files ( -type f ) in this ( . ) directory and in all sub directories, the filenames are then printed to standard out one per line. This is then piped | into (word count) the option tells wc to only count lines of its input. Together they count all your files.

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment