LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   counting number of files (https://www.linuxquestions.org/questions/linux-newbie-8/counting-number-of-files-159227/)

akin81 03-17-2004 10:29 PM

counting number of files
 
Is there a command in Linux counting the number of files in a directory and all its subdirectories?

Kovacs 03-17-2004 10:46 PM

ls -R | wc -l

akin81 03-18-2004 01:25 AM

Quote:

Originally posted by Kovacs
ls -R | wc -l
is there a better solution in stead of counting number of lines?

Demonbane 03-18-2004 01:49 AM

maybe
Code:

find . -type f | wc -l
?

that doesnt count symbolic links though

Tinkster 03-18-2004 01:56 AM

None I know of in standard installations ... but you
can probaly write something in C.


Cheers,
Tink

jkunkel 03-25-2004 01:48 PM

Counting number of files
 
Here is a small script to count the number of files directories and sym links in a directory.

----------------

let COUNT=0

for i in $1/*
do
let COUNT+=1
done

echo $COUNT

----------------

example command:

count ./

with a few more modifications to the script it could count all files in sub directories also.

Enjoy!

Tinkster 03-25-2004 01:53 PM

Re: Counting number of files
 
Quote:

Originally posted by jkunkel
----------------

let COUNT=0

for i in $1/*
do
let COUNT+=1
done

echo $COUNT

----------------
You sure that's more efficient than
Code:

ls -R | wc -l
? :)


Cheers,
Tink


All times are GMT -5. The time now is 02:03 PM.