Find The Last Filesystem Check

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:

The output should look similar to this:

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:

The output will look weird, but it’ll confirm that tune2fs is installed. 

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 CTRL + ALT + T and let’s get this party started.

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:

I plugged a bunch of stuff in, so an example output might look like this:

Next, your command looks like this:

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:

On the other hand, an example of a good output might be like this:

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:

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:

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.

Block A Specific Port In Linux Mint

If you’re using Linux Mint, you’ll find you have ufw already installed which means it’s easy to block a specific port in Linux Mint! I’ll explain how to do that in this article and do what I can to make it easy enough for a new Linux user to follow. If this interests you, read on!

You might want to block a port for all sorts of reasons. If you’re open to the public web via your router, you might find bots hammering at the default ports (such as 22 for SSH) trying to find the login credentials, even if none exist. This is unnecessary traffic and can cause the system to slow down if it’s overwhelmed with connection requests.

Also, Linux uses a lot of ports. There are a bunch that are reserved, for example. You can also designate your ports for many things. I’ve written articles about ports before, so here’s some light reading material:

How To: Check If A Specific Port Is Open
How To: Scan A Remote Host For Open Ports
Find Out What Process Is Listening On A Specific Port
Prevent Brute-Force SSH Attacks With fail2ban

About Ports:

Now, I think I’ll let an AI tell you what a port is in Linux.

A Linux port is a virtual concept that helps access different services within a network. A port is a 16-bit integer ranging from 0 to 65535 with no physical existence.

A port acts as a communication endpoint for identifying a given process or application on the Linux operating system. A port is a 16-bit (o to 65535) number that differentiates a single application from others on various end systems.

As the blurb says, these are virtual ports. They’re not like the physical ports on your router, or anything like that. They’re used for communication and sending traffic to a specific port is asking for traffic on that port. 

If you have nmap installed, you could run nmap localhost to find out which ports are open on your computer. You probably should run that command (you’ll need to install nmap with sudo apt install nmap before you can run this command in Linux Mint). If the port isn’t open, then you don’t need to block that specific port.

UFW:

Linux Mint comes with ‘ufw’ already installed. It is not enabled by default, however. It’s good that it comes installed, which means it’s almost ready for use and you only need to enable ufw for it to be of use. If you don’t know what ufw is, you can check the man page with man ufw to learn more. For simplicity’s sake, you’ll find that ufw is described as:

ufw – program for managing a netfilter firewall

We will be using ufw to block a specific port in Linux Mint. You’ll learn that ufw stands for “Uncomplicated Firewall” and is a frontend for iptables. You can do anything with iptables that you can with ufw, but ufw is much easier for a new Linux Mint user. It doesn’t need to be complicated, as you’ll see in this article.

Use UFW To Block A Specific Port In Linux Mint:

While there is a GUI front-end for ufw, we won’t be using that. Instead, we’ll just use the installed terminal and ufw. As you’re using Linux Mint, you can open your default terminal by pressing CTRL + ALT + T.

With your terminal now open, we first need to enable ufw because ufw is not enabled by default. To enable ufw, run the following command:

That will enable ufw on system startup. That command should output something that looks like this:

You can later disable ufw if you find you no longer wish to use it. That command would look like this:

Now, to block a specific port in Linux Mint with ufw, the syntax would be easy enough to figure out. It just looks like this:

If you want to block the default SSH port (port 22) then you can do that like so:

If you change your mind at a later date, the command to undo this would be:

All you need to do is remember ‘deny’ and ‘allow’ and that ufw commands require elevated permissions which means you need to use sudo. If you can remember that, you can block and unblock specific ports in Linux Mint!

Closure:

Yes, this article is about blocking a specific port in Linux Mint with the ufw command, but it applies to many other distros. I just happened to be using Linux Mint when I wrote the article and didn’t want to test on other systems before smashing the schedule button. So, I wrote it specifically for Linux Mint. This will likely be an accurate tutorial for Ubuntu, the official Ubuntu flavors, other Ubuntu derivatives, and maybe Debian. I’m not sure about Debian.

And now you know…

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.

How To: Enable NTP In Linux

Time is very important to the Linux operating system so keeping accurate time is important, which is why we want to enable NTP in Linux. This won’t be a major article and it should be simple enough to follow along. It’s pretty easy to enable NTP in Linux.

If you don’t know, NTP stands for Network Time Protocol. This allows your computer to connect to a networked device that tells your computer the accurate time and then syncs your computer’s clock with that accurate time.

This networked time server is usually just on the public web, but you could do things like run your own NTP server with a GPS device. (GPS uses really, really, really accurate time. In fact, that really accurate time is how GPS works.) Your company may even run its own NTP servers, but there are plenty of public servers available.

While we’re on the subject, your Linux computer keeps time in a very funny fashion. It counts the seconds since the epoch. The “UNIX Epoch” is an arbitrary date and time. Specifically, it counts the seconds since January 1st, 1970 at 00:00:00 UTC. I’ll write an article on the subject at some point. It is also sometimes referred to as “POSIX Time”. In the meantime, you can always look it up at your favorite search engine. 

Time is very important to Linux. After all, the kernel is a task scheduler. It’s also important for accurate record keeping, among other things. It’s also not difficult to enable NTP in Linux.

NOTE: This article assumes you’re using systemd, as most mainstream distros do. If this isn’t true, this article isn’t for you.

Enable NTP In Linux:

Yes, this is another article that requires an open terminal. You can usually just press CTRL + ALT + T to open your default terminal. If that’s not true, fix the keybindings!

If you’re a desktop user, you can probably skip this article. If you’re a desktop Linux user, odds are good that your distro came preconfigured to sync the time already. Let’s go ahead and verify that with this command:

What you’re looking for is these lines:

You’re especially interested in the last line. If that line says that the NTP service is active, you can ignore this article and read one of the prior articles on the timedatectl command:

How To: Find Your Timezone In The Terminal
How To: Change The Timezone

If the NTP service is not active, you can start the service with this command:

That’s all you need to do to enable NTP in Linux.

If you want to disable NTP, that’s just as easy. That command looks like this:

Next, you can run this command to confirm that you’ve enabled NTP:

That should output information that says the NTP service is active. It may not say that the clock has synchronized as that may take some time before the scheduled task runs and syncs your time with a dedicated time-keeping server.

If you want to muck about with the settings, they’re viewed here:

You’d edit that file with Nano, or some other terminal text editor. Before doing so, you should first read the man page, with this command:

There you go! You can enable NTP in Linux!

Closure:

It seems that I’ve developed a few different styles for my article writing. Longer articles get treated differently, as in they’re formatted differently. The shorter articles have been formatted like this for quite a while. I think that’s a comfortable mix, though it is (as always) subject to change. As I learn and grow, so too may the formatting.

Anyhow, this seemed like a fun article to write. I doubt it’ll be all that popular. It’s unlikely to rank all that well in the search engines. Still, it’ll be information that’s on the site, and the more information I have the better I think I’ll be doing.

It’s not always about the traffic. Indeed, it was never really about the traffic. The traffic is secondary. My primary objective is to share information. Today’s article covered how to enable NTP in Linux. Further, it is limited to just those who use systemd.

Most of my readers will have no use for this information. But, there will be someone – and maybe only that one someone – who will find this information and need it to enable NTP on their Linux device. Good. To that reader and my regulars, I say thanks for visiting.

Now my usual blurb at the bottom of every article…

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.

A Quick Look At The Cat Command

If you want to view the contents of a text file in Linux, you have something called the ‘cat’ command. Being able to use the cat command is important. This article will give you a quick look at the cat command. After all, this was written during the weekend and a quick article seems like a good idea.

It’s possible to view text in the terminal. Many files are just that, able to be read as text. This isn’t true for all files, of course. Trying to read a .tar.gz file as text is unlikely to be fruitful. On the other hand, a .sh file would be trivially read as plain text.

When you’re manipulating text in the terminal, you want a tool like Nano. When viewing text in the terminal, you can use a tool like the cat command. It’s a handy tool.

The cat Command:

You shouldn’t have to install anything. If you enter cat --version in the terminal, you’ll get an output like this:

As you can see, the cat command is a part of the GNU core utilities and, as such, should be installed on almost all Linux systems by default. This means you won’t need to install anything.

If you check the man page, with man cat, you’ll see that it’s described like so:

cat – concatenate files and print on the standard output

Other than the big word concatenate (which means to link files together), you can see that this is the correct tool for the job. What you type in is standard input and what comes out in the terminal is standard output. (That’s often referred to as stdin and stdout, respectively.)

As we’re going to be taking a quick look at the cat command, you might as well understand what it’s for and what it’s expected to do.

Using The cat Command:

As suggested above, this requires an open terminal. Press CTRL + ALT + T and your terminal should open. That’s not always true, but it’s true more often than not.

With your terminal now open, let’s start with something you should have – that is a ~/.bash_history file. If you don’t have a ~/.bash_history, pick a different text file that’s in your current directory (PWD) by using the ls command to search for such. You might have a ~/.bashrc for example.

Now, let’s just view that ~/.bash_history file in your terminal.

If you’re like me, that’s a great deal of text. You’ll need to scroll up to view all of the text, but the cat command is pretty helpful like this.

Let’s say you wanted to create a new file. You may want to read this article:

How To: Write Text To A File From The Terminal with “>” and “>>”

Using the information from that, you can use the cat command to create a new file with this command:

So, try the following:

You should see that there’s now a file named ‘foo’ in your PWD.

There’s a lot one can do with this cat command. You can show the contents of more than one file at a time, like so:

Using the same concepts from above, you can even use > or >> to take the output from cat and insert it into another file.

Finally, and cat has so much more to offer – but this is just a quick look – you can tell cat to number the lines in the output. For example:

See? Nice and easy! The cat command will happily show the output with line numbering enabled. This stuff is easy enough to commit to memory because the cat command is surprisingly powerful for such a little command.

Closure:

So, yeah… It’s a weekend. I have written some larger articles during the past few weeks. That means an easy day is always welcome. Don’t forget that you can make it easier on me by writing an article for the site! I do welcome contributions and it doesn’t matter much if it’s something I’ve already covered – so long as you do a better job than I did!

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.

Change Between CLI and GUI Mode

If you use Linux you’re probably familiar with the CLI (Command Line Interface) and a GUI (Graphical User Interface, but you can also change between CLI and GUI mode. With a simple terminal command, you can change between CLI and GUI mode at will.

Now, this isn’t talking about switching to a TTY. That’s another option and you can switch between them just as easily, perhaps even easier. I think I’ll touch on TTY first.

TTY:

TTY stands for Teletype with origins back when teletype terminals were how you interacted with a computer. There’s still some use for TTY, typically when the GUI has issues responding (at least at my house).

If you want to visit the TTY, read all these directions.

Let’s enter tty3. Press CTRL + ALT + F3.

Congratulations, you’re in tty mode. You can log in and run commands. The output of such will appear on your screen.

Now you’re stuck. This is why you read the directions first.

Most often, you can press CTRL + ALT + F7 to return to the desktop.

If that doesn’t work, press CTRL + ALT + and keep pressing over and over again until you return to a graphical environment. As this is not standardized, you may need to press various combinations of the CTRL + ALTFunction Keys or even the back arrow button. No, I do not know why this isn’t standardized.

That’s all well and good, but we’ll be showing you how to change between CLI and GUI mode with init and changing your runlevel.

Runlevel:

You’ll need an open terminal for this. You can usually press CTRL + ALT + T to open your default terminal.

With your terminal open, you can check your current runlevel. To do that, you just run runlevel in the terminal. If you do so, you’ll likely find out that your runlevel is 5, which is where it should be as my readers are generally GUI desktop users. It looks like this:

If the output is a 3, you’re in CLI mode.

Change Between CLI And GUI Mode:

By keeping that terminal open AND reading the directions before acting on this information, we can start switching between CLI and GUI modes. You want to read all the directions so that you don’t get stuck so that you’re able to find your way back to the GUI mode.

Very simply, 3 is CLI and 5 is GUI. Got it?

If you’re in a CLI mode (and a GUI is available) you can switch to the GUI mode with the following command:

If you’re in a GUI mode and you want to switch to a CLI mode, the command is just as simple. You just need to change the value, like so:

That’s all you need to know if you want to change between CLI and GUI mode. It’s not very complicated, though you should make sure you know how to return to the previous mode so that you’re not stuck and need to reboot your computer to return to your more comfortable GUI mode.

Well, that’s a short article!

Ha, just kidding!

Change Between CLI And GUI Mode (With systemd):

Most users can be assumed to be using systemd at this point. If you’re not sure if you’re using systemd, you can run the following command:

If you’re using systemd, the output should look like this:

Now, you can use systemd to change between CLI and GUI mode. To ensure you can return to a GUI mode after running this command, you should probably read the entire directions for doing this with systemd.

If you’re in CLI mode and you wish to switch to a GUI mode (again, assuming such is available – which it may not be on servers), the command is quite simple. Just run:

If you’re in GUI mode and you want to switch to CLI mode, the command is quite similar. That command looks like this:

See that? There’s a way to change between CLI and GUI mode with systemd and it’s quite an easy task. These commands are easy enough to remember, though you could always add them to your handy notes so that you have these commands available when you can’t recall them off the top of your head.

There are times when a GUI is better than a CLI. There are times when a CLI is better than a GUI. Then, for example, there are times when a full screen of text is better than just using a terminal. If you’re processing a lot in the terminal, using a full-screen CLI isn’t necessarily a bad idea. You’d certainly not be alone in doing so.

Closure:

I expected to split this into two different articles, but I decided to add the bit about systemd to this article as it was simply too short without it. I’ve been trying to ensure my articles are 800+ words, more often than not, and folks seem to appreciate the longer articles with more information.

This site has been and always will be, a work in progress. I learn and grow as I write these articles. This is reflected by the changes I make along the way. I’m sure that I’ll continue to grow for as long as I write these articles. I’m equally sure that things will change as time passes.

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.

Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.