chandan
chandan

Reputation: 19

How to get the file size in shell script?

How can I get the size of all the log file(.log) inside the directory /Test? where Test* means Test-1 and Test-2 and Test-3 ...

Thanks and Regards, Chandan

Upvotes: 0

Views: 1371

Answers (2)

James Brown
James Brown

Reputation: 37404

Using stat and awk for summing:

$ stat -c "%s" foo bar |awk '{i+=$1}END{print i}'
570

Upvotes: 1

RomanPerekhrest
RomanPerekhrest

Reputation: 92854

du command:

du -shc /Test/Test* | tail -1

Replace the path /Test/Test* with your actual path(the needed folder)

An exemplary output should be like below:

144K    total

-c - to get a grand total file size


http://man7.org/linux/man-pages/man1/du.1.html

Upvotes: 2

Related Questions