How to get correctly directory size ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to get correctly directory size ?
# 1  
Old 04-04-2012
How to get correctly directory size ?

Hello,

I am on solaris 9 (KSH) and I am on trouble while using a command line in a script to get the directory size of a directory.

Code:
/usr/bin/du -sk /data/_restit
typeset -i rep_size=` /usr/bin/du -sk /data/_restit |cut -d"/" -f1 `
echo "${rep_size}"

I did try different way to write the command line get the size Smilie each time the size given is not the real size like if I do from the shell :

Code:
du -sk /data/_restit

Thanks for your help
# 2  
Old 04-04-2012
How about:
Code:
du -sk /data/_restit | cut -f1

# 3  
Old 04-04-2012
Hello Scrutinizer,

This will not work better, I already try !

Is there a way to get the directory size in another way of using
Code:
du

?

Thanks
# 4  
Old 04-04-2012
Quote:
Originally Posted by Aswex
Hello Scrutinizer,

This will not work better, I already try !
What was your code and output did you get?
# 5  
Old 04-04-2012
Hello CarloM,

It seems that the size given on the script is the size of one of the subdirectory. The only way to solved my problem was to add
Code:
cd

to reset the path were stop the script.Strange isn't it !

The script it's just dowloading files and put them in different directories then ends by showing the size of the directory that contain all sub directories with files inside.
# 6  
Old 04-04-2012
It might be strange if I understood what you'd written Smilie.

Please paste the output you're actually getting from du -sk /data/_restit.

Is the number you want the total size (i.e. recursively, including sub-directories), or something else?
# 7  
Old 04-04-2012
Here is the output from the shell :

32320

Here is the output given from the script :

2198

By using
Code:
cd

to reset the curent path used by the script to put the last file the problem is solved, but I am not completly satisfied.

Problem solved for now, thanks

Last edited by Aswex; 04-04-2012 at 08:58 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Ls directory size reporting byte size instead of file count

I have been searching both on Unix.com and Google and have not been able to find the answer to my question. I think it is partly because I can't come up with the right search terms. Recently, my virtual server switched storage devices and I think the problem may be related to that change.... (2 Replies)
Discussion started by: jmgibby
2 Replies

2. Shell Programming and Scripting

Can't add directory to path correctly

Hello everyone I am a newcomer to UNIX and I have hit a snag in something that would probably take experienced people about 30 seconds. Long story short I am trying to add a directory to my PATH and it is getting added but not working. I mean, the object of adding it to the path is so I can access... (2 Replies)
Discussion started by: tastybrownies
2 Replies

3. Shell Programming and Scripting

How to delete some of the files in the directory, if the directory size limits the specified size

To find the whole size of a particular directory i use "du -sk /dirname".. but after finding the direcory's size how do i make conditions like if the size of the dir is more than 1 GB i hav to delete some of the files inside the dir (0 Replies)
Discussion started by: shaal89
0 Replies

4. Solaris

get directory size

Hi, How to get size of particular directory? Thanks (5 Replies)
Discussion started by: cutefriend
5 Replies

5. UNIX for Dummies Questions & Answers

directory tree with directory size

find . -type d -print 2>/dev/null|awk '!/\.$/ {for (i=1;i<NF;i++){d=length($i);if ( d < 5 && i != 1 )d=5;printf("%"d"s","|")}print "---"$NF}' FS='/' Can someone explain how this works..?? How can i add directory size to be listed in the above command's output..?? (1 Reply)
Discussion started by: vikram3.r
1 Replies

6. Solaris

Directory size larger than file system size?

Hi, We currently have an Oracle database running and it is creating lots of processes in the /proc directory that are 1000M in size. The size of the /proc directory is now reading 26T. How can this be if the root file system is only 13GB? I have seen this before we an Oracle temp file... (6 Replies)
Discussion started by: sparcman
6 Replies

7. Shell Programming and Scripting

size of directory

Hello again; I have a directories and subdirectories in my current directory and i wanna to find the directories( and subdirectories ) which are larger than what user enters as first parameter. find . -type d -size +"$1"c -print > directories.dat I used this command and i am not sure it is... (19 Replies)
Discussion started by: redbeard_06
19 Replies

8. UNIX for Dummies Questions & Answers

directory size with ls -l

am I right in assuming that in unix a directory size is just information about that directory stored somewhere on the file system, and not a sum of its contents? This is because ls -l gives 1024 as my directory size, when the directory contains many gigs worth of stuff. also, is du -sk dir ... (2 Replies)
Discussion started by: JamesByars
2 Replies

9. Solaris

How to correctly allocate size while creating FileSystem

Hello - I am finding difficulty in creating and allocating correct size to File Systems on solarix x86 box. Please see below contents I followed on screen and in the end It shows that /app file system is created of size 135GB , I wanted it to be 30gb as mentioned during 'format' command in 'Enter... (7 Replies)
Discussion started by: panchpan
7 Replies

10. UNIX for Dummies Questions & Answers

size of a directory?

hi, say i have the following directory structure a/b/c/d... can i do df -kt /a/b/c/d and the output will gives me the total space of the directory space in d? or the output will just be the total space of the parent directory a. hope its clear.. (2 Replies)
Discussion started by: yls177
2 Replies
Login or Register to Ask a Question