No matter how well you take care of your computer, sometimes, it will just crash and you often have to pull off the plug to restart the computer. When such crashes happen, there is a chance that your filesystem will get corrupted or damage. It is advisable to do a filesystem check regularly to make sure that it is running properly and free of error.
In Linux (and Mac), there is this powerful command “
fsck” that you can use to check and repair your filesystem. “Fsck” stands for “File System Consistency checK”.
An important thing to note is that fsck cannot be used on a mounted partition. If you do so, there is a high chance that it will damage the filesystem.
Full article here:
Check and Repair Your Filesystem With fsck [Linux] (Make Tech Easier)
One thing the article doesn’t mention is that you can avoid the problem of not being able to use fsck on a mounted partition by causing the system to reboot and then immediately run fsck. To do that, issue this command from the command prompt:
shutdown -rF now
The “-r” option means “Reboot after shutdown”, and the “-F” option means “Force fsck on reboot.” The two options can be combined into “-rF” as shown above. Unfortunately, that only works in Linux, not OS X, but if you’re already booted into OS X you can use Disk Utility to check your filesystem, and then you don’t even need to reboot.