bash script directory size


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash script directory size
# 1  
Old 03-23-2011
bash script directory size

hello!

i need to make a script that get a folder name in parameter and i get back the size of the folder include the subfolders! but i dont know how i need to start :S

Example:
a folder contain the followings
Code:
a:
drwxr-xr-x 2 user user 4096 febr 25 08.27 b
-rw-r--r-- 1 user user 2 febr 24 14.29 valami.txt

there is a b folder in the a folder that contains these:
Code:
-rw-r--r-- 1 user user 63206 febr 24 14.29 en3700.pdf
-rw-r--r-- 1 user user 20532 febr 24 14.29 info_bucsu.odt
-rw-r--r-- 1 user user 2 febr 24 14.29 más.txt

and the script have to work like that: i have give the Folder name as parameter to the script and that give back the size of the folder(s).
Code:
$ ./sum.sh a
83742

thx the help

Last edited by Scott; 03-23-2011 at 06:14 PM.. Reason: Please use code tags
# 2  
Old 03-23-2011
You don't need a script for that at all.

Code:
du -s foldername

will sum up the size of the folder and things inside it, reporting in 512-byte blocks. If you want it to report in human-readable numbers, add -h.

Note that it's disk used, which can be subtly different from the precise byte count of all the files but is a more accurate reflection of its actual disk footprint.
# 3  
Old 03-23-2011
that is my script:
Code:
#!/bin/bash

DIRSIZE=`du -bs $1 | cut -f 1`

echo $DIRSIZE

Code:
~$ ls -lR h867879
h867879:

Summary: 8

-rw-r--r-- 1 h867879 hallgato 536 2011-03-23 17:14 h867879.sh

h867879@linux4:~$ bash kotprog2.sh h867879
4400

and 536 not equal with 4400 :S

Last edited by Scott; 03-23-2011 at 06:15 PM.. Reason: Code tags
# 4  
Old 03-24-2011
Quote:
Originally Posted by Corona688
Note that it's disk used, which can be subtly different from the precise byte count of all the files but is a more accurate reflection of its actual disk footprint.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bash script to get total size off of remainder calculated

I am working on a script to get the final total size and so far have the following and wondering if this can be improved. # Compare the desired size of each lvm to the standard size. If it is desired is larger than calculate the difference and keep that value as the amount to add to that LVM. ... (5 Replies)
Discussion started by: user3528
5 Replies

2. Programming

Cant remove directory on bash script

hi all, this is my script and as you can see in the screenshot i attach its not deleting the directory in the source folder #!/bin/bash cd /vol/cha-work/_ARCHIVE/to_be_archived/audio/robert_test temp=/mnt/robert_test/temp dest=/vol/cha-archive/audio echo "is this archive for an... (2 Replies)
Discussion started by: robertkwild
2 Replies

3. Shell Programming and Scripting

Bash Script - File Size

I have a bash script. I need a modification for safety. my original bash script: mv /home/script/backup /home/script/backup2 mysql -u user -ppassword -Ddatabase --batch --skip-column-names -e 'select id, url from videos where url like "%http%" limit 1' | while read id url do youtube-dl... (1 Reply)
Discussion started by: tara123
1 Replies

4. 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

5. Shell Programming and Scripting

Need help in finishing a bash script for listing subfolder by size in a large folder

Greetings everyone. I have seen that you do wonders here. I have a large folder on a Ubuntu linux. Organization main folder, inside 20 000 subfolders, and inside those subolders many other like 5-6 folders and files. I am interested to create an output to a txt file under the bash... (2 Replies)
Discussion started by: ultimo
2 Replies

6. Shell Programming and Scripting

Script to monitor directory size of specific users

Hi, i am new to shell scripts, i need to write a script that can monitor size of directory of specific users. Please help. Thanks, Nitin (2 Replies)
Discussion started by: nicksrulz
2 Replies

7. 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

8. 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

9. Shell Programming and Scripting

to write a script to compare the file size in the current directory and previous dir

hi, i am new to this site. i want to write a script to compare the file size of the files in the current dir with the files in the previous directory. the files name will be same, but the filename format will be as xyzddddyymm.txt. the files will arrive with the month end date(i want to... (5 Replies)
Discussion started by: tweety
5 Replies

10. Shell Programming and Scripting

bash script working for small size files but not for big size files.

Hi, I have one file stat. Stat file contents are as follows: for example. H50768020040913,00260100,507680,13,0000000643,0000000643,00000,0000 H50769520040808,00260100,507695,13,0000000000,0000000000,00000,0000 H50770620040611,00260100,507706,13,0000000000,0000000000,00000,0000 Now i... (1 Reply)
Discussion started by: davidpreml
1 Replies
Login or Register to Ask a Question