troubleshooting Question

Need help modifying my script

Avatar of YZlat
YZlatFlag for United States of America asked on
Unix OSShell Scripting
15 Comments1 Solution362 ViewsLast Modified:
I need to write a script that loops throught all the directories that contain $var in the path and get all the files with .txt extension and calculate the total size


for example if $var="sample" and directories below contain

/u01/test/samples

test1.txt 1GB
test2.txt 1GB

/u04/data/sample

sample2.txt 2Gb

then the script should add up file sizes in those directories and assing them to a variable

So far I came up with something like this:

$dir=/u01/test/samples/*.txt
du -g $dir | total_size=`awk '{c+=$1};END { print c }'`

which works great but only returns total file size for one specified directory. Can someone help fix my code so that it returns total size fo all directories containing a specific variable in the path?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 15 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 15 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros