for p in $@;
do size = '(ls -RFsh $dval | grep \/$ | awk '{ print $1 }' '
((totalsize = totalsize + size))
echo "$size"
done;
echo "$totalsize "
with that i got size not found [no such file / directory]
anyone got any idea why?
im trying to add up the size of the directory and print up total
can you post the output of below command
ls -RFsh $dval
Documents/Music:
Documents:
total 16k
4.0k Music/ 4.0k Pictures/ 4.0k Templates/ 4.0k Videos/
Documents/Music:
total 0
Documents/Pictures:
total 0
Documents/Templates:
total 0
Documents/Videos:
total 0
so, you want to sum the total values ?
total 16k
total 0
total 0
total 0
total 0
with grep \/$ it i will print
4.0k
4.0k
4.0k
4.0k
but size doesnt record it :S
---------- Post updated at 04:50 AM ---------- Previous update was at 04:49 AM ----------
yeh, but im suppose to record selected file size and total only those etc
in Document if i wan Music and Picture only the total size will be 8
---------- Post updated at 04:51 AM ---------- Previous update was at 04:50 AM ----------
was gonna do another grep just to pick up selected arguments
are you trying to calculate the directory size ? ( which the path was passed as argument ?)
yeh
was gonna do ./calculate -d Documents -t Music Picture
this command will printout total size of Music + Picture directory
without using du tho
can you change the below line
do
size=$(ls -RFsh "$dval" | grep \/$ | awk '{ print $1 }')
i tried adding bracket.. but doesnt work..
by doing
size=$(ls -RFsh Documents | grep \/$ | grep Music | awk '{ print $1}')
it will printout 4.0k, need to record that and addup to next argument, since i already used for loop to cycle through the arguments
but the size wont record it
@CarloM
exercise and practice lol
1) you need to remove the K from the 4.0K ( before you are adding )
2) you may get the result with M (Mega) and G (Giga) also. ( how you will handle in this case ? )
CarloM
April 3, 2012, 6:16am
12
You need to strip off the units and convert to a common unit before you try and add it to a total (you could have 3.6M, 4.0K, etc).
1 Like
ah so without the human readable.. lets see
i dont think, this command will give the correct size.
I Guess, it is giving the number of blocks. ( not the size )
size=$(ls -RFsh Documents | grep \/$ | grep Music | awk '{ print $1}')
1 Like
yeh i changed it, now it's working fine...
ls -s Documents | grep DesiredFile | awk '{ print $1 }')
---------- Post updated at 05:24 AM ---------- Previous update was at 05:23 AM ----------
thanks alot itkamaraj and CarloM
CarloM
April 3, 2012, 6:30am
16
You could save a command/pipe by just passing the filename into awk for use as a pattern.
size=$(ls -RFs $dval | awk -vval=$name '$0 ~ val { print $1 }')
1 Like
oh yea that works too.... haha never really think of using awk that way, i newbie in this hehe