Now, we are going to write step by step a Linux script to check the disk:
#!/bin/bash
# Check disk space
df -h
# Check disk usage for specific directories
du -sh /path/to/directory1
du -sh /path/to/directory2
# Add more directories as needed
# Check disk health using SMART (requires smartmontools package)
smartctl -a /dev/sda
# Replace /dev/sda with the appropriate device for your system
# Check disk read/write performance using hdparm (requires hdparm package)
hdparm -Tt /dev/sda
# Replace /dev/sda with the appropriate device for your system
# Check disk I/O statistics using iostat (requires sysstat package)
iostat
# Check disk read/write errors using dmesg
dmesg | grep -i error
# Check filesystem errors using fsck (may require unmounting the filesystem)
sudo fsck -y /dev/sda1
# Replace /dev/sda1 with the appropriate partition for your system
# Check disk temperature using smartctl (requires smartmontools package)
smartctl -A /dev/sda | grep -i temperature
# Replace /dev/sda with the appropriate device for your system
Save the script in a file, e.g., check_
disk.sh
, and make it executable using the command chmod +x check_
disk.sh
. Then, you can run the script by executing ./check_
disk.sh
in the terminal.
Keep in mind that some commands might need admin rights (like sudo
) or certain packages installed on your system. Change the commands based on your needs and the tools available in your Linux distribution.