Database Administration (MOSC)

MOSC Banner

KSH script to get file size for multiple directories

edited Dec 17, 2013 12:22AM in Database Administration (MOSC) 5 commentsAnswered
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 directory. Can someone help fix my code so that it returns total size fo all directories containing a specific variable in the path?

Howdy, Stranger!

Log In

To view full details, sign in to My Oracle Support Community.

Register

Don't have a My Oracle Support Community account? Click here to get started.

Category Leaderboard

Top contributors this month

New to My Oracle Support Community? Visit our Welcome Center

MOSC Help Center