Skip to content

Instantly share code, notes, and snippets.

@Delnegend
Last active July 15, 2024 09:33
Show Gist options
  • Save Delnegend/f26bc17532cd2aaa1718ccd5e2d508f8 to your computer and use it in GitHub Desktop.
Save Delnegend/f26bc17532cd2aaa1718ccd5e2d508f8 to your computer and use it in GitHub Desktop.
Calculate the TBR and TBW of an SSD, requires `smartmontools` to be installed.
#!/bin/bash
# Change this to the SSD you want to check
drive="/dev/sda"
# Extract the sector size and LBA written from the output
sector_size=$(sudo smartctl -Ai $drive | grep 'Sector Size' | awk '{print $3}')
lba_written=$(sudo smartctl -Ai $drive | grep 'Total_LBAs_Written' | awk '{print $10}')
lba_read=$(sudo smartctl -Ai $drive | grep 'Total_LBAs_Read' | awk '{print $10}')
# Calculate TBW and print the result
tb_write=$(echo "scale=2; $sector_size * $lba_written / 1024^4" | bc -l)
tb_read=$(echo "scale=2; $sector_size * $lba_read / 1024^4" | bc -l)
echo "TB Read: $tb_read TiB"
echo "TB Write: $tb_write TiB"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment