ztank1013
ztank1013

Reputation: 7245

Counting files contained in a directory

How can I count all files, hidden files, directories, hidden directories, sub-directories, hidden sub-directories and (symbolic) links in a given directory using bash?

Upvotes: 4

Views: 266

Answers (4)

Walter A. Aprile
Walter A. Aprile

Reputation: 131

You can also use

tree

it gives you a count in the end. I don't know how the speed compares with find. Lazily:

tree | tail -1

easier to type than find :-)

Upvotes: 0

user25148
user25148

Reputation:

find . -print0 | tr -cd '\0' | wc -c

This handles filenames with newline characters.

Upvotes: 4

Arnaud Le Blanc
Arnaud Le Blanc

Reputation: 99919

This does it:

find the_directory|wc -l

This works be finding all files in the directory, and counting them.

Upvotes: 2

Mike Sokolov
Mike Sokolov

Reputation: 7054

find . | wc -l

This will count each symlink as a file. To traverse symlinks, counting their contents, use:

find -L . | wc -l

Upvotes: 6

Related Questions