Directory sizes


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Directory sizes
# 1  
Old 09-24-2003
Directory sizes

Can someone tell me how to read these damn sizes.

i mean, i prefer to see sizes in MB but that is not the case when you do an ls -l on directories. i have a had time converting these to MB

just for verification purposes, what would a directory size like this = 3499990308 represent in MB
or something like this 29994??

or is there a rule i can follow to be able to calculate this crap on my own? honestly, if any revision needs to be made to unix, it should be the ability to make all these sizes VERY easy to read. unix is complicated enough to be wasting time on this nonsense
# 2  
Old 09-24-2003
i make it this way:

GNU bash, version 2.05.0(1)-release (sparc-sun-solaris2.9)

# mkfile 56k test1
# mkfile 5354k test2
# ls -lh
total 10832
-rw------T 1 root root 56K Sep 24 14:40 test1
-rw------T 1 root root 5.2M Sep 24 14:41 test2
# 3  
Old 09-24-2003
........

by the way:

the "-h" is also useable for this output:

root@pressy.ips.at # df -h /dev/dsk/c0t0d0s0
Filesystem size used avail capacity Mounted on
/dev/dsk/c0t0d0s0 2.0G 2.0G 0K 100% /


greetings Preßy
# 4  
Old 09-24-2003
Preßy,

ls -h is available only on GNU ls. So that is not a very general answer. Besides, the real thrust of the question is the mental conversion of bytes to megabytes.

3499990308 as displayed by ls represents bytes. To get it to megabytes, I want to drop the last 6 digits. 3499990308 is sort of how I "see" the number. Now I do evaluate that 990308 as I throw it away. I do that really by looking just at the leading nine. Since I am throwing away a "large" number, I add one to the number that I keep. 3499 + 1 = 3500 MB. Whether or not to add that one depends on the leading digit of what I threw away. If it's 5,6,7,8, or 9 then I add the one.

This is a compromise, I would use a more accurate algorithm if I were writing a program. But I can do this instantly and effortlessly.

Effectively, what I have done is to divide the number by 1,000,000. Perfect accuracy would have required dividing by 1,048,576. Using the bc program I see that the real answer is 3338 MB. With a file this big, I don't care about a lousy 162 MB.

29994 is too small. Well, ok, it is 0 MB. I simply never want to convert tiny sizes to megabytes. But kilobytes would work in this case. The rule is similiar to the above, but here I just drop 3 digits rather than 6. So I estimate that file at 30 KB. bc says the real answer is 29 KB. Again, close enough.

Notice that both of my estimates were high. That is guaranteed to be the case.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Partition Sizes

Good Morning, What's a good way to get partition/slice sizes down to the byte on Solaris 9? I've tried a few ways, but only see results like 8.21GB which rounds the number. Thanks! (5 Replies)
Discussion started by: Stellaman1977
5 Replies

2. Shell Programming and Scripting

How to list files names and sizes in a directory and output result to the file?

Hi , I'm trying to list the files and output is written to a file. But when I execute the command , the output file is being listed. How to exclude it ? /tmp file1.txt file2.txt ls -ltr |grep -v '-' | awk print {$9, $5} > output.txt cat output.txt file1.txt file2.txt output.txt (8 Replies)
Discussion started by: etldeveloper
8 Replies

3. UNIX for Advanced & Expert Users

df vs du for directory sizes

Is it better to use df or du to calculate directory sizes? I tried both and got different numbers with both. $ du -h /home 1.7G /home/bob1 1.7G /home $ df -h /home Filesystem Size Used Avail Use% Mounted on /dev/mapper/VG-lv_home 25G 1.9G 22G ... (2 Replies)
Discussion started by: cokedude
2 Replies

4. UNIX for Dummies Questions & Answers

Compare two file sizes.

Hi everyone! I need to compare two file sizes. One of them (size) will be stored in a flat file and the other coming from a listed file. I can now get the first file size using: SIZE=`ls -l $DOCTYPE | awk '{print $5}'` 1. How can I store this value in a flat file? 2. How... (2 Replies)
Discussion started by: mrreds
2 Replies

5. Shell Programming and Scripting

Help with file sizes

I have 2 big files in the size of gb. They are same with respect to content, both are “,” delimited. Now both of them are created by two different processes but has the same logic. The problem is they are differing only in few bytes for e.g one file is 202195751 bytes other is 202195773. So... (2 Replies)
Discussion started by: dsravan
2 Replies

6. UNIX for Dummies Questions & Answers

Directories sizes

Hello everyone, can anybody help me in finding a way to obtain a list of all the directories and their sizes. I would like to be able to run this and obtain an output like a tree structure with each branch saying how much space it is taking up . Hope you can point me in the right direction.... (1 Reply)
Discussion started by: gio001
1 Replies

7. Shell Programming and Scripting

Directory sizes loop optimization

I have the following script: #!/usr/bin/ksh export MDIR=/datafiles NAME=$1 SERVER=$2 DIRECTORY=$3 DATABASE=$4 ID=$5 export dirlist=`/usr/bin/ssh -q $ID@$SERVER find $DIRECTORY -type d -print` for dir in $dirlist do SIZE=`</dev/null /usr/bin/ssh -q $ID@$SERVER du -ks $dir` echo... (6 Replies)
Discussion started by: la_womn
6 Replies

8. Shell Programming and Scripting

to compare total directory structure and get sizes of all f on two different servers

Hello every one, Iam newbie to this forum and shell programming &scripting. i needed to compare each and every folder of two separate servers. Actually I have copied some directory structure from one server to second server, to build on second server the files all should be copied... (3 Replies)
Discussion started by: mannam srinivas
3 Replies

9. Shell Programming and Scripting

Script for checking and reporting file sizes in a directory.

Hi, Need help for a Script for checking and reporting database file sizes in a directory. Request you to please give your valuable inputs. Thanks a lot in advance. Best Regards, Marconi (1 Reply)
Discussion started by: marconi
1 Replies

10. UNIX for Dummies Questions & Answers

Help on adding file sizes

Hi I need to take a list of files that are defined by an ls -ltr or grep for particular file names - and add up the byte size colum which is field 5 seperated by a space. I tried to do this but I think I am way off: for file in 'ls -ltr | grep 20070916 | nawk -F" " '{temp+=5} END {print... (1 Reply)
Discussion started by: llsmr777
1 Replies
Login or Register to Ask a Question