As with any suspected filesystem corruption, the first thing you have to do is check the filesystem. For ext2/3/4 filesystems, the normal tool for doing this is
e2fsck, a particular form of fsck.
This utility should be installed by default on any GNU/Linux system. The catch is that you need to unmount the filesystem in order to check it.1 With regard to the Raspberry Pi, this probably means you will have to take the SD card out and put it in another computer and do the check from there.
If you do not have another linux box to use, create a live CD -- most distro install disks currently function as such, I think -- or use a virtual machine implementation such as VMware or VirtualBox, with which you can run a linux system within OSX or Windows.
There are many explanations of
e2fsck online as well as a man page. You may want to try and back stuff up off the partition first, if possible, if you haven't kept it so already, as the repair may result in lost files. By "stuff" I do not mean the entire partition, just your own data.
If you want to skip all the "Should I fix this?" questions from fsck (which may be copious), use
sudo e2fsck -y /dev/sdb2
Remeber, it's the second partition on most pi cards, such as Raspbian, that is the root filesystem. You should probably check the first one as well, with
If the repair succeeds but there were a lot of questions, there may have been data loss meaning stuff may still not work. Also look in the
lost+found directory on the partition, which will contain unidentified file fragments from lost data.
1. This is not quite true -- you can force it to work on an fs remounted read-only. The problem with that is if the filesystem is sufficiently corrupted (such that
sudo doesn't work), it could effect the functionality of fsck, and it also can create problems if the filesystem needs repair.