If you’ve been using Linux for any time, you may have done a filesystem check and today we’ll find out when you did the last filesystem check with the Linux terminal. This may seem a little complicated, at least at the start, but it should be relatively easy. New Linux users should be able to follow along as we try to make Linux more approachable.
Disks have corruption after a while. Given enough time and data, a filesystem check is likely. Fortunately, Linux has many tools that will help you verify the integrity of your data. These tools are generally installed by default, so we shouldn’t need to install any new tools in this tutorial.
The article will have been tested in Lubuntu. The directions in this article are going to work with Ubuntu, official Ubuntu flavors, Linux Mint, ElementaryOS, and many more distros. I’d say they’re fairly generic instructions and that all these tools will be installed by default in most major distros.
You need good data health. This isn’t about hardware health as much as you’d learn from S.M.A.R.T data, it’s about the integrity of your data. You might use the information from this article to decide to run an fdisk command or two. Of course, you might also be interested in one of my more popular articles:
Repair Your Linux Filesystem With a Live USB or DVD
What we’re going to do is find out when the last filesystem check. What you do with that information is up to you.
We will be using some tools…
lsblk:
The first tool we’ll be using is one of the default Linux tools. The name of that tool is lsblk. You can verify that lsblk is installed with the following command:
1 | lsblk --version |
The output should look similar to this:
1 2 | $ lsblk --version lsblk from util-linux 2.37.2 |
If you run man lsblk in the terminal, you’ll find that it’s described as this:
lsblk – list block devices
We’ll be using this lsblk command to identify drive names. It’s not complicated and you’ll be able to follow along easily enough. I’m sure of it!
tune2fs:
We’ll also be using the tune2fs command in this exercise. As far as I can tell, tune2fs doesn’t have a formal version flag. If you run a typical version command against it, it does spit out the version but it also spits out some usage information. So, that will do for verifying that you do indeed have tune2fs installed. You can run this command:
1 | tune2fs -v |
The output will look weird, but it’ll confirm that tune2fs is installed.
1 2 3 4 | $ tune2fs --version tune2fs 1.46.5 (30-Dec-2021) tune2fs: invalid option -- '-' <snip> |
Of course, the man page describes tune2fs like this:
tune2fs – adjust tunable file system parameters on ext2/ext3/ext4 filesystems
While that might not seem useful, it is. We’ll be using it to get those system parameters to find out when you did the last system check. Trust me! It’ll come in handy.
We’ll also be using a pipe and grep, but we’ve used those many times before.
Find Your Last Filesystem Check:
If it’s not obvious, we’ll be using the terminal for this. So, press
The first thing you do is you want to identify the name of the drive. Don’t blame me for calling it the name. That’s what the command outputs. That’s what I’m calling it. The command for this is nice and simple, just run this command:
1 | lsblk |
I plugged a bunch of stuff in, so an example output might look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | $ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sda 8:0 0 476.9G 0 disk ├─sda1 8:1 0 512M 0 part /boot/efi └─sda2 8:2 0 476.4G 0 part / sdb 8:16 0 3.6T 0 disk ├─sdb1 8:17 0 991.1G 0 part /media/kgiii/elements1 ├─sdb2 8:18 0 984.6G 0 part /media/kgiii/elements2 ├─sdb3 8:19 0 976.7G 0 part /media/kgiii/elements3 └─sdb4 8:20 0 773.6G 0 part /media/kgiii/elements4 sdc 8:32 1 14.4G 0 disk └─sdc1 8:33 1 14.4G 0 part /media/kgiii/FLASH DRIVE sdd 8:48 1 58.6G 0 disk └─sdd1 8:49 1 58.6G 0 part /media/kgiii/DISCOVERY sr0 11:0 1 1024M 0 rom |
Next, your command looks like this:
1 | $ sudo tune2fs -l /dev/<name> | grep Last\ c |
This isn’t always going to spit out the right information. If a drive isn’t an EXT* formatted partition/drive, it’s not going to spit out any useful information. There will be no information if you try to use it with your EFI partition, for example.
An example EFI command and output might be:
1 2 | $ sudo tune2fs -l /dev/sda1 | grep Max tune2fs: Bad magic number in super-block while trying to open /dev/sda1 |
On the other hand, an example of a good output might be like this:
1 2 | $ sudo tune2fs -l /dev/sda2 | grep Last\ c Last checked: Tue Aug 1 23:38:39 2023 |
As you can see, that was checked just a couple of months ago.
Alternatively, as I plugged some rather random stuff into the USB ports, you might see something as old as this:
1 2 | $ sudo tune2fs -l /dev/sdb3 | grep Last\ c Last checked: Fri Jan 29 12:50:49 2021 |
That’s been a minute or two since the last filesystem check.
If you’re using an NVMe M.2 SSD, this will still work:
1 2 | $ sudo tune2fs -l /dev/nvme0n1p1 | grep Last\ c Last checked: Wed Dec 7 20:57:10 2022 |
So, it’s not all that difficult to find out when you did your last filesystem check.
Closure:
Careful observation may show you that the site has changed a little. There’s now a way to do sponsorship, seeing as I get asked so many times. Nobody ever follows through, but I have had some contact with a couple of agencies. You may start seeing sponsored content soon. Feel free to about sponsoring Linux-Tips if you want.
As for the article, it’s just another easy enough article. I hope I’ve distilled it down enough to make it approachable for even the newest Linux users. It may be good to check to see when you performed your last file system check. If you have data in cold storage, you may want to check that now and again and check your filesystem’s health once in a while. The goal is to prevent data loss through corruption and this should help with that.
Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.