I am trying to create a startup shell script to run udate; autoclean; autoremove; and fstrim at startup. Below is what I've come up with. Can someone validate my syntax and confirm where this script should be placed (i.e. etc/init.d)?
#!/bin/sh
run update, autoclean, autoremove and fstrim on system at startup
Running the fstrim command on SSDs in Linux is still beneficial for maintaining optimal performance and extending the lifespan of the SSD. Modern Linux distributions, such as Ubuntu and Fedora, typically have fstrim scheduled to run automatically on a weekly basis via a systemd timer or cron job. This automation helps ensure that unused blocks are discarded regularly, which can improve write performance and wear leveling.
However, it’s important to verify that your SSD and filesystem support TRIM. You can check if TRIM is enabled by running:
sudo hdparm -I /dev/sda | grep TRIM
If your system is already set up to handle TRIM operations automatically, manually running fstrim might be redundant. Additionally, ensure that you’re not running fstrim during intensive operations, as this could impact performance.
In summary, while fstrim is still necessary for SSD optimization, many modern Linux distributions handle it automatically. If your distribution does not have fstrim enabled by default, you can enable it using:
This is something I haven't had to think about, since I was on Windows, and I had to do what is known as defragging, cause the Windows NTFS system was so inefficient, you'd develop file system issues, within only days!
On Linux, it never seems to be an issue, since Linux uses a GPT4 file system, and in its nature, doesn't to screw me over. But out of curiosity, I ran that command, and I discovered that my NVME drives auto trim weekly.