| Author |
How to get Size of directory/folder in linux?
|
Rahul Dhaware
Greenhorn
Joined: Aug 13, 2008
Posts: 22
|
|
How to get Size of directory/folder in linux? I want to store folder size in variable in shell script. But how can i do this?
|
 |
Charles Lyons
Author
Ranch Hand
Joined: Mar 27, 2003
Posts: 836
|
|
How about "du -s DIR" where DIR the directory path. You can also use the --si flag to get a "human readable" version, or -b for the length in bytes. So something like: [ December 12, 2008: Message edited by: Charles Lyons ]
|
Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
|
 |
Rahul Dhaware
Greenhorn
Joined: Aug 13, 2008
Posts: 22
|
|
Hi Charles Lyons, I tried like dir="/path/to/dir" size=`du -bs "$dir"` but then i got size = 843M . but i can't understand why there is "."(dot). Actually i want only 843M like size=843M. Please can you help me in that?
|
 |
Charles Lyons
Author
Ranch Hand
Joined: Mar 27, 2003
Posts: 836
|
|
|
which should produce a result in bytes... that's the point of the -b argument. If it is still providing a result like 843M and not 843123456, then your version of du is different to mine (which is GNU coreutils v5.97). Check the manpage for your version. Unless you want the value with the k/M/G suffix?
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 14472
|
|
That "dot" is your directory name. In this case, it's the relative location of your current working directory. If I do a "du -bs /var/log, I should get something like: 123765 /var/log as a result. Here's one way to get the value as a number: DIRSIZE=`du -bs $dir | cut -f 1`
|
Customer surveys are for companies who didn't pay proper attention to begin with.
|
 |
Rahul Dhaware
Greenhorn
Joined: Aug 13, 2008
Posts: 22
|
|
Thanks Tim...... It's works.
|
 |
 |
|
|
subject: How to get Size of directory/folder in linux?
|
|
|