Total HDD size and count on Linux machine

Thread Tools Search this Thread
Operating Systems Linux Red Hat Total HDD size and count on Linux machine
# 1  
Old 11-14-2013
Total HDD size and count on Linux machine

I am trying to grab two information
1. Total size of HDD
2. Total number of HDD (if possible alongwith names)

can someone suggest me how can we do that in linux machine..
though small scripts and commands like

# 2  
Old 11-14-2013
You need to be root to run fdisk, there's safer ways in modern Linux. You can run this as a normal user:



# The special /sys/ folder contains device information, not actual files.
for DEV in /sys/class/block/sd*
        [[ -f "$DEV/start" ]] && continue       # Skip partitions
        read B < $DEV/size                      # Read num of blocks
        read MODEL < $DEV/device/model          # Read model

        printf "%-40s%15d blocks %5d GB\n" "$MODEL" "$B" $((B/(1024*1024*2) ))
        ((BLOCKS+=B))   # Add to total

printf "%-40s%15d blocks %5d GB\n" "total" "$BLOCKS" $((BLOCKS/(1024*1024*2)))

This also helps avoid picking up unintended things like software RAID devices.
These 2 Users Gave Thanks to Corona688 For This Post:
# 3  
Old 11-18-2013
thank you very much Corona688 for teh script...but could you provide me some script which can determine Total size of HDD ...script which can use the below output of fidisk command :
[root@VM172016001140 tmp]# fdisk -l
Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        5222    41838617+  83  Linux

# 4  
Old 11-18-2013
In what way does my solution not work for you?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count total duplicates

Hi all, I have found another post threads talking about count duplicate lines, but I am interested in obtain the total number of duplicates. For example: #file.txt a1 a2 a1 a3 a1 a2 a4 a5 #out 3 (lines are duplicates) Thank you! (12 Replies)
Discussion started by: mikloz
12 Replies

2. UNIX for Dummies Questions & Answers

Ls directory size reporting byte size instead of file count

I have been searching both on 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

3. Solaris

How to count total HDD size of disk?

Hi, I am trying to fetch total HDD size through command line on solaris machine: bash-3.2# iostat -E sd0 Soft Errors: 0 Hard Errors: 0 Transport Errors: 0 Vendor: VMware Product: Virtual disk Revision: 1.0 Serial No: Size: 42.95GB <42949672448 bytes> Media Error: 0 Device... (1 Reply)
Discussion started by: omkar.jadhav
1 Replies

4. Red Hat

USB HDD not showing valid partition on one Solaris machine

Hi All, We have got a USB HDD with important data in it. The data has been copied to the disk(formatted ext3) via a LINUX system. The data was supposed to be copied to a second LINUX machine. Surprisingly, it doesn't show up any valid partitions in the new box. dmesg: usb1-3:... (2 Replies)
Discussion started by: Bikash Mishra
2 Replies

5. Linux

Istallation Of PCLinuxOS 2009 Onto A HDD-less Machine...

I have no idea if this has been done before but I have an Acer Aspire One - NG5, 512MB RAM, netbook where the SSD failed and is now FIXED DISKLESS and unable to boot until now... ;o) It ran PCLinuxOS 2009 as its OS until the SDD failure... The method is a little long winded and does require a... (0 Replies)
Discussion started by: wisecracker
0 Replies

6. Shell Programming and Scripting

Total Count using AWK

Discussion started by: sraj142
8 Replies

7. Shell Programming and Scripting

total size

I have a directory that contains files like aaa-2010-05-30.txt ddd-2010-05-30.txt www-2010-05-30.txt i have total 2000 files, i need to calculate total size of files for *2010-05-30.txt like aaa-2010-05-30.txt 200MB ddd-2010-05-30.txt 10GB www-2010-05-30.txt 4GB Total 14.2 GB... (5 Replies)
Discussion started by: learnbash
5 Replies

8. Shell Programming and Scripting

Bogus Total count

I have a shell script that I am pulling different zip file packages and totaling how many of each type of package is in the directory. I get a bogus total count of one in the middle of my output file (highlighted in RED) and not sure why, also would like to get a grand total of all files but not... (2 Replies)
Discussion started by: freddie999
2 Replies

9. Solaris

command to find out total size of a specific file size (spread over the server)

hi all, in my server there are some specific application files which are spread through out the server... these are spread in folders..sub-folders..chid folders... please help me, how can i find the total size of these specific files in the server... (3 Replies)
Discussion started by: abhinov
3 Replies
Login or Register to Ask a Question