I'm working on an assignment, and I'm stuck on one point. I'm trying to return the sum of the size of all files in a directory (including sub directories). The du command is not allowed.
Consider the following directory structure:
My specific question is, how do I add the entire tree to a list in my script such that I can work with them the get the size. I can get the size once there.
So far I have the following:
echo "Enter Directory Name:"
set mydir = $<
echo "Calculating the total of the size of all files in the directory tree"
set mysum = 0 #variable to hold sum
set filelist = $mydir
set mycursize = 0 #variable to hold current filesize
foreach x ($filelist)
@ mycursize = `stat -c%s $x` #finds current filesize
echo "size of $x is $mycursize"
@ mysum = $mysum + $mycursize #accumulator
echo "The sum of the size of all files in this directory is: $mysum"
When I search testdir I currently get the size of only that directory, of course.
I've tried setting filelist = `ls -R $mydir`which does add all the subfiles, but when I run my script is says "No such file or directory" for every item in the list.