PDA

View Full Version : Using stat?



indarkness
April 30th, 2010, 06:52 AM
Hi, I have a little question.
I need to know the size of a directory, and the number of element that it has got.
I've proved with stat which shows the size of the dir,but that function shows me more what i need, and i've thoutgh to use "cut" to delete the colums i don't need.
To show the number of elements in te directory, how can i do? I know i cojos use "ls",but i only want the number of element not a list of them.
Thanks

lostinxlation
April 30th, 2010, 07:06 AM
ls <dir> | wc -l

Ibidem
April 30th, 2010, 07:08 AM
Maybe
ls |wc -w
(number of "words" in output of ls)
or
ls -l -A|head -n 1
(I think that's files & folders added up)

soltanis
April 30th, 2010, 07:33 AM
Try du.



du | awk '{ acc += $1 } END { print acc / 1024 "M" }'

dragos2
April 30th, 2010, 08:50 AM
Or simpler:


du -ch