Find the answer to your Linux question:
Results 1 to 9 of 9
sfdisk -s The above command provides whole drives with their size in blocks ...How can i find the size in bytes ? Thanks, karana...
  1. #1
    Just Joined!
    Join Date
    Jul 2008
    Posts
    24

    [SOLVED] linux finding all drives .

    sfdisk -s

    The above command provides whole drives with their size in blocks ...How can i find the size in bytes ?



    Thanks,
    karana

  2. #2
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    If you run it with 'sfdisk -l', you will get a line like
    Code:
    Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0
    There you have the size of a block.

  3. #3
    Just Joined!
    Join Date
    Jul 2008
    Posts
    24

    scripts to get it

    That is great .But unluckly my box linux doent have sfdisk .

    I am going for fdisk -l

    i would like to write a script that will provide me --disk name and disk size --in two dimensional arry or in a map .

    i am new to scripting .

    i tried
    fdisk -l | grep Disk | grep "byte" | awk '{ print $1}
    but i dont know how can i make it in an arraray.


    I think i suceeded in conveying my questions in a good english . i wrote below to make u understand ...Sorry for my bad english .

    clarification on "array"
    string name[10];
    int size[10] ;

    for each i in name , correspoding i th element size indicates its size .....

  4. #4
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    Erm, are you aware of "df -h"?

  5. #5
    Just Joined!
    Join Date
    Jul 2008
    Posts
    24

    i am not mounting devices

    i want to know full disk size ...and i am not mounting devices.

  6. #6
    Just Joined!
    Join Date
    Jul 2008
    Posts
    24
    but using df -h ,i can see only disk partions ..not disk size whole

  7. #7
    Linux User
    Join Date
    Jun 2007
    Posts
    318
    Here's a sample script that does what you want:

    Code:
    #!/bin/bash
    
    typeset -i CT=0
    TMPFLE=/tmp/tmp.tmp
    
    fdisk -l | grep "^Disk" > $TMPFLE
    while read LNE
        do
            CT=CT+1
            DSK[$CT]="`echo "$LNE" | awk '{print $2}'`"
            SZE[$CT]="`echo "$LNE" | awk '{print $5}'`"
            echo "${DSK[$CT]} ${SZE[$CT]}"
        done < $TMPFLE
    echo "Disks found: $CT"

  8. #8
    Just Joined!
    Join Date
    Jul 2008
    Posts
    24
    Your answer is very interesting ....

    Without creating tmp file , Can we do this ?

  9. #9
    Linux User
    Join Date
    Jun 2007
    Posts
    318
    Quote Originally Posted by 91change View Post
    Your answer is very interesting ....

    Without creating tmp file , Can we do this ?
    Go to this tread for details:
    http://www.linuxforums.org/forum/lin...thin-loop.html

    EDIT: Forgot to mention that bash only supports one dimension arrays.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...