Skip to content
Related Articles

Related Articles

Improve Article

Shell Script to Check Hard Disk Revolutions Per Minute (RPM) Speed

  • Last Updated : 30 Jun, 2021

RPM is an acronym for Revolution Per Minute. RPM is the number of revolutions a hard disk makes in a single minute. Normally, the higher the RPM of a disk the better it is, however with higher RPM comes higher cost. Below is a shell script to check the RPM of a hard disk.

Using hdparm command:

hdparm is an acronym for hard disk parameter. hdparm is a command-line utility widely used for performing analysis on the disks that a user system has. It can help us to get statistics about the hard disk, modify writing intervals, and DMA settings. It is used to display and alter the SATA/IDE device parameters.

Syntax

hdparm [option] [device]

Here, in our case, our hard disk is at “/dev/sda”.  It is just the Linux/Unix way of naming disks just like Windows has C: D: drives. Similarly, in Linux, we have sda, sdc,sdb, etc and /dev is the directory for where these drives are.

To list all the disks that you have in your system, run the following command:



sudo lsblk

Output:

Marked HDD

Here, marked one is my hard disk drive, and you can see the name of the drive is assigned as sda.

Shell script to know the RPM speed of an HDD

Script:

#!/bin/sh

# shell script to find the RPM speed of a Hard disk

# storing hard disk name into variable disk
disk="/dev/sda"

# finding the Rotation speed of the hard disk 
# fetching the integer value 
# i.e. the speed of the hard disk 
# and saving it into another variable
output=$(sudo hdparm -I $disk | grep Rotation | grep --only-matching --extended-regexp '[0-9]+' )

# Displaying the RPM speed of the hard disk
echo "The RPM speed of the Hard disk is: $output rpm"

Note: You have to enter your password after running this script. And ‘-I’ flag in the hdparm means that we are fetching information from the disk live and in this statement “grep –only-matching –extended-regexp ‘[0-9]+'”,  “–only-matching” will fetch the rotation speed with the extra string output with it by using “–only-matching” with “–extended-regexp” with the pattern “[0-9]+” we are ensuring only the numerical value to display i.e. the rpm speed, “[0-9]+” will fetch any numerical value in the pattern it will match for any integer value from 0-9 and the “+” symbol shows that it can match any number of occurrences more than 1.

Output:

Speed of the Hard disk

My Personal Notes arrow_drop_up
Recommended Articles
Page :