Remove Unused Kernels From RHEL

Today’s article is only going to apply to some of you, specifically those who use RHEL and want to remove unused kernels from RHEL. That’s a pretty narrow subset of people, but it’s worth knowing this information if you’re a RHEL user.

Red Hat is one of the oldest Linux distributions out there. Along the way, they’ve turned into an ‘enterprise’ (business class) distro. They’ve made some strange strategic decisions lately, but I’m not going to get into that in this article.

As an enterprise distro, it is not entirely free (as in cost in dollars). They are a distro that has a great deal of support for long periods. They’re meant to be stable and ideal for business use. You’re expected to pay for RHEL – sort of.

RHEL has a free version if you sign up as a developer. You can learn about the RHEL developer program at this link. I thought it was free for a few devices, but it looks like I might be wrong and that it may be more than that. From the linked page:

An entitlement to register 16 physical or virtual nodes running Red Hat Enterprise Linux.

So, that’s more than three – but you’re not going to get support. If you want to go this route, you’re expected to support yourself. Fortunately, RHEL has extensive documentation and your dev subscription will get you access to any of that documentation that’s behind a paywall. Or, at least that’s my experience.

I don’t do enough with RHEL!

Linux Kernels:

I’ve explained what the kernel is before. Linux is just the kernel. We add stuff to the kernel to make an operating system. We then add more stuff to make it a specialized operating system – such as a desktop operating system, like the readers of this site use.

Along the way, as you update and upgrade, you’ll add new kernels. These are not necessarily removed by default. They can take up quite a bit of space and you might be paying for that space (especially if you’re using RHEL as a server somewhere). So, removing the oldest kernels is just good housekeeping.

That’s all we’re doing in this article. I suppose it’d probably also work for CentOS but I don’t pay any attention to that distro these days. It’s not that I’m angry or annoyed with RHEL’s decisions, it’s that I only care for things with long-term support. I’m old and changes scare me!

We’re just going to clean up any old kernels, probably while keeping the 2 most recent kernels, to keep things nice and orderly. This isn’t something you technically have to do. You can keep all the kernels you want. But, if you want to remove unused kernels from RHEL this might be the article for you!

Remove Unused Kernels From RHEL:

Now, if you’re using RHEL as a server then you’re already connected via SSH (probably) and already have a terminal open. If you’re using RHEL as a desktop OS, you will need to open a terminal. You can just press CTRL + ALT + T and your terminal will pop open.

With your terminal open, you first need to install yum-utils. That’s nice and easy, just use this command:

(You’ll need elevated permissions unless you’re logged in as root.)

Next, run the following command to see how many kernels you have installed:

If you have more than two kernels installed, you can run this command:

You can adjust that command if you’d like. That particular command will keep the kernel you are currently using and the previous kernel. (You can boot to older kernels via GRUB if you want. That article is actually about recovery mode on Ubuntu, but the pictures should clue you in until I write an article just for this purpose.)

If you use a --count= of 1 or 0, it will remove every kernel except the one in use, it will not remove the kernel that’s in use.

That’s all you have to do. There’s nothing more to it. The command will automatically remove older kernels at the level you decided. You can keep the most recent three kernels, four kernels, or however many kernels you want. It’s not terribly complex.

Closure:

I don’t do a whole lot of RHEL articles, but it’s nice to at least write one here and there. If you’ve got extra kernels, you now know how to remove unused kernels from RHEL. It’s a pretty easy task and something even a new user can handle. If you’re a new user, go for it! It won’t break anything – in and of itself. (I’d highly recommend keeping the current kernel and the most recent kernel, just in case.)

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.

Let’s Make The rm Command A Little Safer

In today’s article, we will discuss a simple trick that will help you make the rm command a little safer. This isn’t something everyone will do, but it might be something a cautious user might do. It might also be something a new user might want to consider doing. After all, you can’t be too safe!

Now, when I say safe, I mean preventing you from accidentally removing files you don’t want to delete. I do not mean safe as in security. I mean safe as in preserving data that is important to you. This isn’t a foolproof method, but it gives you a chance to rethink things.

Obviously, we’ll be using the rm command. Don’t worry, that’s not something you’re going to need to install. It’ll be there with your distro as a part of the standard tools, probably from the nice GNU folks.

For those that don’t know, the rm command is a terminal-based command used to remove files and directories. It does exactly what you tell it to do and sometimes you may tell it to do things you don’t want it to do. Either way, the man page (man rm) describes the rm command succinctly:

rm – remove files or directories

See? Nice and simple.

We’ll also be adding an alias. I intend to write a good article about aliasing things, but this is not that article. Don’t worry, you won’t need to know a whole lot about aliases in order to follow along with this article. I’ll make it nice and simple.

Make The rm Command A Little Safer:

As mentioned in the preamble, the rm command is used in the terminal. So, of course, you’ll need an open terminal for this one. It won’t be too complicated, so press CTRL + ALT + T and your default terminal should open. If it doesn’t, find it in your software menu and open it that way.

NOTE: This article relates to the removal of files over which you the user have control, eg ~/home/<your-username>. If you’re removing files with sudo, root, or as another user, the rm command will function as normal.

Alright, so what’s an alias? An alias is a substitution. You can create an alias that inputs ‘foo’ even though you typed ‘bar’, and that’s the trick we’ll be using to make the rm command a little safer for you. If you don’t do this and you remove important files, all I can say is I told you so! 

I’m going to assume that you have Nano installed. If you do not have Nano installed, you can use a different text editor. For simplicity’s sake, we’ll just go over doing this with Nano.

Let’s Install Nano (With Some Bonus Information)

With Nano installed, your first command is going to be opening up your ~/.bashrc file for editing. You do that with this command:

Yes, the . means that it is a hidden file, but Nano finds it just fine.

Now, you want to use the arrow keys to scroll to the absolute bottom of that file and add the following line:

Next, you’ll save the edited .bashrc file by pressing CTRL + X, then Y, and then ENTER.

With that done, you’ll need to tell the system to reload the .bashrc file. You do that with this command:

Now, when you use the rm command, it will add the -i flag. This will show you the files that the rm command is going to delete and give you a chance to back out of it.

Closure:

See that? You’ve now managed to make the rm command a little safer and you’ve added an alias to the rm command. Pretty neat, I think. This means that you’ve got that second chance when you misfire an rm command. It also means you get to really think about it and that the process doesn’t run without your giving it confirmation to do so.

One of these days I’ll figure out how to write an article about aliases. They’re really handy things to have around and you can use them for all sorts of neat things. I suppose you could just search for that information. Other people have written articles on the subject, probably better than I will. So, there’s always that option… Which is nice…

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.

Manage Files In A tar Archive

Today we’ll have a fairly simple article, albeit a bit archaic, as we learn how to manage files in a tar archive. We often work with modern compression methods but tar files still exist and are in wide use. If this is something you’re interested in, this is the article for you. If this isn’t something you need right now, remember this article and look it up later when you do need to manage files in a tar archive.

Sure, tar now often ends with .gz or .bz, but they still exist. You’ll still see them and you’ll still get regular questions about them. In fact, a lot of folks will ask questions like, “How do I install files from a .tar file?” Alas, that’s a pretty broad question and not something we’ll answer here. However, the answer is, “Manually.” That’s how you install files from a tar file, generally speaking.

What Are tar Files?

So, I’m pretty sure we’ve covered this before, but ‘tar’ stands for ‘tape archive’ and is a pretty old standard. Yes, I am well aware that tape archives still exist. There’s no reason to leave a comment telling me that. I know, but I suspect most tar files never see a tape throughout their entire lives. If you’re curious, the man page describes the tar application as this:

tar – an archiving utility

The format has been around since 1979, though it has undergone some changes along the way. If you’re interested, there’s an excellent Wikipedia article about tar files. It’s well worth skimming it, as I did when I wrote an earlier article.

Basically, tar is a way to organize multiple files into a single file. Tar files are not compressed in and of themselves. We more often see them compressed with .gz (or the like) but the format doesn’t include compression of any kind. It is also meant to work with any file system, as it contains no real file system in and of itself.

Well, eventually you may want to work with tar files. You may want to add, remove, or modify tar files. That’s all easily done within the Linux terminal and this article will show you how.

Manage Files In A tar Archive:

Obviously, you need a terminal for this application. By now, regular readers will know how to open a terminal. In most distros and desktops, you can just press CTRL + ALT + T and, with that, the default terminal will pop open.

With your terminal now open, let’s go ahead and create a new tar file to mess around with…

Now, we’re all set for this exercise…

Add Files To A tar File:

So, it’s easy enough to add files to a tar file. The syntax to do so is quite simple, though you do need a few flags.

Of course, you can add multiple files by just adding their file name. Using the files you created in the first step, you’d add files to a tar file like so:

To avoid any confusion later, we’re now going to clean up after ourselves, leaving just the foo.tar file.

Now, in your terminal you can type the following:

In the list of files, you should now only have the foo.tar file remaining. For neatness sake, this is an important step. You can list the files in a tar file with the following command:

The output should look like this:

See?

Remove A File From A tar File:

Now that you have created a tar file and added files to it, you next need to learn how to remove a file from a tar file. That’s actually a very simple process. The syntax is as follows:

So, using our current example file, we’d do something like this:

You can check again to see that the foo3 file no longer exists.

Still with me?

Well then, the next logical step in this process would be learning how to…

Change Files In A tar File:

If a file already exists in a tar file, you will first need to extract that file. You can do so easily. Use the tar -tvf <file_name>.tar to find the specific file’s name. With the name of that file, you can extract it with this command:

So, using the example file that we’ve worked through, we’d change the file called foo2 by first extracting it, like so:

That will extract the foo2 file from the archive. You can then edit that file, say with nano, to make it say what you want it to say. Feel free to do so, but you must remember to save the file after you’re done editing the file. (To save files in nano, press CTRL + X, then Y, and then ENTER.)

Now, you just replace the file with the file you’ve edited. In this case, it’d be foo2 that you’ve edited. The syntax is pretty easy:

So, in our case, you’d be replacing foo2 with the previous foo2 file. That’s a nice and simple command. To finish the exercise, you can run this command:

Be sure to check the man page to learn what the flags do and to see the many other options that come with your tar application. It should absolutely be installed by default, on even the most bare of distros.

Closure:

So, well, I figured this would be a fun article to write. I was not wrong. If you want, you can clean up after yourself with this command:

I figured it’d be a fun article for folks to follow and wrote it in a way that I hope facilitates that. There’s nothing all that complicated about it. If you want to manage files in a tar archive, this is a good way to do it. You could probably do it with a GUI, but this way is just as good – I think.

Also, this was the article I wanted to write last time. You got a meta article because of my poor internet connection. This was the article I’d hoped to write. It’s quite a bit different than most of my articles, but hopefully, it takes you clearly from the start to the finish – including cleaning up after yourself!

As always…

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.

Find And Remove Duplicate Files With fdupes

Today’s article has you cleaning up your storage space as you learn to find and remove duplicate files with fdupes. This isn’t something you need to do often and it’s something that could theoretically break your system. If you’re going to remove duplicate files, it’s a good idea to exercise some caution.

I’ve previously shared another way to remove duplicate files:

Find And Remove Duplicate Files With rdfind

I suppose it’s pretty obvious as to why one might want to remove duplicate files. You do so to keep your storage tidy and you do so to make space when space is limited. There are all sorts of ways to make free space and removing duplicate files is just one of them.

The tool we’ll be using this time around is known as ‘fdupes’ and the man page describes it like this:

fdupes – finds duplicate files in a given set of directories

It’s an easy enough application to install and this article shouldn’t be all that long. You’ll find that fdupes is available in your default repositories, or there’s a good chance that it is in there. Of course, this means it’s easy enough to install.

Installing fdupes:

You can install fdupes with a GUI and your software manager, but you can just as easily install it via the terminal. We’ll cover the latter, as it’s the most universal (and, I find, quickest) method. Of course, you’ll need an open terminal. In most cases you can just press CTRL + ALT + T and your default terminal should open.

With your terminal now open, let’s go ahead and install fdupes:

Debian/Ubuntu/derivatives:

SUSE/OpenSUSE/derivatives:

RHEL/Fedora/Rocky/derivatives:

Arch/Manjaro/derivatives:

Gentoo/Calculate/derivatives:

And More! (Just search your default repositories for ‘fdupes’ and it’ll almost certainly be there.)

As you can see, you’ll find that fdupes is available for pretty much every Linux system out there. Not only is it available, it’s already packaged for you and easy enough to install via the terminal. On top of that, it doesn’t take much space to install fdupes, a mere 110 kB or so.

NOTE: I do not have anything against GUI tools. While I have terminals open at all times, I do the majority of my computer interaction in a browser – specifically a GUI browser. I suggest and write about the terminal because it’s more universal. It’s also often faster, assuming you can type or at least cut and paste than it is to go mucking about with a GUI software installer.

Anyhow, it’s nice and easy to remove duplicate files with fdupes. This article is going to show you how – and the article shouldn’t even be that long! It’s pretty simple.

Remove Duplicate Files With fdupes:

I’m going to assume that you left your terminal open after installing fdupes. If you didn’t, you’ll need to open it again. The only way to run the fdupes application is in the terminal. So, even if you installed it with a GUI, it’s a CLI tool and you’ll need the command line to use it.

The basic syntax is pretty easy, and not entirely unlike rdfind. For example, if you want to find duplicate files, you simply run this command:

So, if you wanted to find duplicates in your home directory, you’d run this:

Don’t worry, you’re safe running that command. That won’t delete anything at all. That fdupes command will simply show you the duplicate files that it found.

If you want to run the fdupes command recursively, that is to check all the folders within the directory, you’d run the command like this:

If you want to calculate the size of the files that would be removed when removing the duplicates, the command is just this:

A summary is also available with this command:

You can also search multiple directories for duplicates. That’d be something like this:

Of course, you can run those commands together to get quite a bit of customization. They’re all reasonably harmless and will simply point out the duplicates as well as some meta information. You can then remove the duplicates by hand if you want.

You can also tell fdupes to remove the duplicates that it found. You’d never want to run this command without knowing what exactly is going to be removed, so don’t do that. Always check to make sure you’re not removing anything of value before automatically removing duplicates.

Fortunately, there’s a bit of a stopgap. You can run the following command and fdupes will ask for confirmation before removing the file:

If you want to go whole-hog and remove every duplicate found, and remove the files without any confirmation, you can run this command:

Of course, that’s just the basics. If you want to know more about fdupes, simply check the man page (man fdupes) for more information.

Closure:

Hmm… I think I need to clean or replace this keyboard. The colon key is sticking on me. It’s a bit of a pain in the butt.

Anyhow, if you’ve ever wanted to remove duplicate files with fdupes, you now have directions to do so. This being Linux, you have all sorts of options when it comes to removing duplicate files, though I again urge caution when doing so. If you were to run this on the root directory, you’d likely find a lot of duplicates, and removing them might break your system. So, be careful with these tools, as they’re pretty powerful.

I’m not yet out of ideas for articles but it’d be great if folks might suggest something they’d like to read about. You never know, it might be something I know about. As it is, I have to search this site before writing an article, or else I’d end up with even more duplicate articles. I don’t want that and you don’t want that. It’s not all that easy to keep up this pace, writing a new article every other day. I’ve managed so far, but I’m eventually going to miss a day or two. It’s going to happen.

As always…

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.

Subscribe To Our Newsletter
Get notified when new articles are published! It's free and I won't send you any spam.
Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.