How To: Delete A Swapfile In Linux

Today’s article will be a bit more advanced than some as I try to explain how to delete a swapfile in Linux. If I do my job right, it’ll be easy enough for a newbie to follow. However, I’m not going to suggest newbies mess around with removing swapfiles – but they certainly can.

It should probably be noted that some folks will call this a “swapfile” and others will add a space to call it a “swap file”. I’m not sure which is correct, so I’m sticking with “swapfile” for consistency sake. After all, about two years ago, I wrote an article about how you can enable a swapfile.

How To: Create And Enable A Swapfile

This article might be a bit complicated. The directions themselves are pretty simple. Distilling the concept of ‘swap’ down to an 800-word article is the difficult part. 

What Is A Swapfile:

What is swap? Well, it’s not really a place where the kernel sticks stuff when there’s no more free RAM. People seem to think that’s what swap is, and it’s not. Even on systems with lots of RAM, the kernel will use swap when it is available.

It’s quite a bit more complicated than that, though it can sort of be related to that. It would be prudent to suggest that you read this thread first, concentrating on the first post in the thread:

To swap or not to swap, that is the question.

I’d further suggest reading this article from the folks at linux.com:

All about Linux swap space

There’s more to it than the article goes into, but pay attention to this bit of text quoted below:

Second, a significant number of the pages used by an application during its startup phase may only be used for initialization and then never used again. The system can swap out those pages and free the memory for other applications or even for the disk cache.

In the early years, we used a special partition for our swap. These days, there probably isn’t much need for a special partition. Most of us that still use swap will be using a swapfile. This is essentially the same thing, but it is a file instead of a special partition on your storage drive.

Your distro may have created a swapfile during the installation process. You may have created your swapfile along the way. Well, this article is going to tell you how to delete a swapfile, just in case you changed your mind.

Delete A Swapfile In Linux:

Yeah, this sort of thing pretty much requires using the terminal. I don’t know of a way to do this graphically, though there’s probably a way that I don’t know about. So, press CTRL + ALT + T to open your terminal and we’ll head straight into the article.

With your terminal now open, let’s first make sure that you have swap to begin with. To do that, you can run this command:

Technically, you don’t need the -m flag, but it’s easier to read in my opinion. The output might look something like this:

As you can see, the system has 16 GB of RAM and 2 GB of swapfile space. Of that 2 GB of swapfile, 737 MB is being used. There’s lots of free RAM, but swap is still being used. Like I said, it’s not just a place where the kernel stuffs things when there’s no more free RAM.

So, now that we’ve learned there’s a swapfile, you can run this command:

The output from that might look something like this:

The bit we’re looking for is /swapfile because that’s the literal name of the swapfile. You could have called it anything while setting it up, so it’s important to get the name correct for the next command.

Now, we want to delete your swapfile. That’s a very easy command. It looks like this command:

In my example, if I wanted to delete a swapfile on my system, the command would look exactly like this:

To confirm that the file is deleted and no longer being used, just run this command all over again:

It might seem a little complicated at first and I hope I explained it well. Using swap (or not) can be a complicated subject, but it’s not all that taxing to delete a swapfile in Linux. If you can follow the above directions, you should be good to go.

Closure:

As I’ve mentioned before, I leave swap enabled because the kernel uses it. The kernel uses swap even on systems with a lot of free RAM. I figure the kernel is smarter than I am, so I leave it enabled.

The second link in this article is well worth reading. Deciding to use swap or not is a very personal thing. If you have plenty of RAM, you can get away with not using any swap at all. Of course, if your system is fast enough and you’re using an SSD, having a swap isn’t going to add much latency to your system – if any at all.

This is something you get to decide. You can decide what is right for you and your computing needs. If you want a swapfile, you can easily add one. If you want to delete a swapfile that was created during the installation, you can do that as well. This is Linux and your configuration options are nearly endless. You decide what’s best for you. You decide how you run your Linux because it is your Linux. And that is awesome.

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 Your Last Boot Time In Linux

It’s a weekend so today’s article will be short and easy, an article for when you want to find your last boot time in Linux. If you want to know when you last booted your computer, there are many ways to get that information. We’ll just cover one way…

We’ve covered a couple of ways to do this in the past. If you want, you can read the following article:

When Did I Last Reboot My Linux Box?

I wrote that article more than two years ago. It was one of my earliest articles. In that article, I covered a couple of different ways that you can find out when you last rebooted your Linux computer. 

In that article, we covered commands like:

There are some advanced commands you can use, so do read the previous article to learn more about how you can find your last reboot time.

In that article, I also mentioned that you could see how long your computer has been on since the last reboot with the uptime command. That’s simply done:

Speaking of the uptime command:

How To: Find Your Uptime In Linux
The Meaning Of “Load Average” On Linux?

Those articles might be of interest. This is a simple article, but it does allow you to read quite a bit more related content.

Find Your Last Boot Time In Linux:

You guessed it. We’ll be doing this in the terminal. That means you’ll need an open terminal. If you’re not sure how to do that, look in your application menu or press CTRL + ALT + T and your default terminal should open.

For this article, we’ll be using the who command. You can check the man page with man who to learn more about the command. If you do that, you’ll learn that the who command is described as:

who – show who is logged on

That may not be as descriptive as it could be. If you just run the following command, you’ll be able to see everyone who is currently logged into your system. That’s just this command:

That simply tells you who is logged in. Your output might look a little like this:

As you can see, I am logged in both on tty7 (the desktop) and tty3.

If you did check the man page, you’d have possibly seen the -b flag. That flag is described accurately:

-b, –boot
time of last system boot

See? Now it should be obvious why I’ve chosen to write this article about how you can find your last boot time with the who command. The command is simply:

Which will output something similar to this:

See? That’s all you need to know if you want to find your last boot time! It’s not all that difficult to get started with the Linux terminal. This is a command any Linux user can learn. It’s also a pretty easy man page to decipher. So, that’d be good for new users as well!

Closure:

It’s a weekend and I’m lazy today. So, you have an easy article. It doesn’t have to be all that easy. I gave you plenty of links that you can (re)visit. Visiting those links will also show you how much the site has changed – specifically with how I write the articles. This particular article is a lot like how I wrote many of the articles, but I’ve been mixing it up quite a bit. I was just really in the mood for an easy article today, so you got this one about using the who command to show when you last rebooted your system.

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.

Yet Another Way To Find Files By Extension

You might look at the title and think that you’ve seen this before, and you have, but this is another way to find files by extension. That’s right! This is Linux! There’s almost always a variety of ways to think about this. There are almost always a variety of ways to accomplish the same task!

Well, this article will touch on a theme we’ve seen before. We’ve seen it recently. I’ve even explained why you might want to find files by their extension type. Fortunately, I’ve even explained the limitations this has.

See a shell script file could have a .txt extension but still work just fine as a script. Linux cares about the file itself more than it cares about the extension. If you have files mislabeled as an .iso file, this operation will still list them as .iso files. This is only about the extension and using that as a search category. It has limitations.

You can read these articles for more:

Another Way To Locate Files By Extension
Find Multiple Filenames By Extension – With Locate
How To: Find Multiple Filenames By Extension

See? It might seem that this article is like beating a dead horse, but it’s not. There are use cases for all of these options, including the option I’ll give you in this article.

Also, it seems like a good day to take it easy. Life has sent me a bit of extra stress. That won’t stop me from writing this article. It seems nothing will stop me from writing these articles!

The ‘ls’ Command:

This is kind of the sledgehammer way to find files by their extension. It’s a good way. It’s even an easy way to remember, without needing extra commands. At the same time, it’s a pretty basic way to do so.

The first command we’ll work with is one you have installed already. You won’t need to add any software to follow along with this article. We’re simply going to use the ls command to list directory contents. 

If you check the man page for the ls command, you’ll see this:

ls – list directory contents

What did I say in the paragraph before that? I said we’re going to list directory contents. Sure enough, Linux provides the perfect tool for this. 

As an aside, what you can accomplish with a basic Linux install is amazing. You can accomplish a whole lot of work without actually adding any additional software. This is awesome. Thank you, Linux.

The ‘grep’ Command:

The second command we’ll be using is the grep command. If you’re a regular on this site, you’ll have used the grep command many times. You can think of the grep command as a filter. You use the grep command to process the output of another command (more often than not) and, more specifically, you use it to filter that output.

You want to use grep when you’re trying to isolate some information. Well, sure enough, we can check the man page for grep. If you do so, you’ll find that grep accurately describes itself like this:

grep, egrep, fgrep, rgrep – print lines that match patterns

You’ll see that grep comes in many forms. You’ll also see that it’s used to print lines that match patterns. The command is filtering out those lines that don’t match the prescribed pattern.

In fact, I used it as an example in the previous article:

Find Out When A File Was Created

Scroll down to see how you can use the grep command to filter out the lines that aren’t important when you simply want to find out when a file was created. Simple, eh? Yes… Simple!

Find Files By Extension:

As you can guess, we’ll be using both the ‘ls’ command and the ‘grep’ command to find files by extension. As those are terminal-based commands, this will be a terminal-based article. You’ll need to open a terminal and you can (more often than not) do so by pressing CTRL + ALT + T.

With your terminal now open, this is the syntax I want you to use for this exercise. We’ll keep it simple:

If you’ve used mix-case, maybe having extensions of .TXT (in capital letters), you can add the -i flag to the grep command. That will (don’t forget to check the man page) tell the grep command to ignore the case. So, an example of the syntax for that command might be:

For example, I might want to search my ~/Downloads directory for .iso files, finding the various distros I’ve downloaded on this computer. If I wanted to do that, my command would look like this:

And, sure enough, here’s an example output from that very command:

See? That output shows you all the .iso files that I have in my ~/Downloads directory. There’s no fuss. There’s no muss. It’s just a simple way to find files by extension.

Anyone can do it and they won’t need any additional software to do so. Everyone (except maybe someone with a very light embedded Linux system – and probably still them) can find files by extension without adding anything to their system. It’s maybe a bit creative, but it’s effective. I’m not sure about you, but I like effective things. This meets that definition squarely – it’s effective.

Closure:

Well, I guess this is still a fairly long article. I’ve been making them longer and this one just got written that way. My style of longer writing isn’t without thought. I have altered the format of these articles a half-dozen times.

Each time I do so, I do so for you. The goal of altering the format is to make it easier for you to digest and to offer more information than previous articles – even for the more basic articles like this one. I do not know if I’ll settle on this style. Evidence would suggest that I’ll improve upon it as I go.

I welcome feedback on this. I don’t suppose you’ll give me that feedback. The odds are good that you won’t even read this far down. Still, please let me know if you like the current writing style. I’ve consistently written to a formula, but that formula has changed over time. This is the most recent iteration, so please let me know what you think. Thanks!

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.

Send A Message To Logged In Users

Today’s article will have limited use for my regular readers, as we talk about how you can send a message to logged-in users. The thing is, this is only valid for those users who are logged into the terminal. It doesn’t pop up a handy GUI window (like the old messenger service from Windows, though I’m sure there’s a way to do so). This is only valid for users who have logged into the terminal.

Got it?

Good!

So, who is this useful for? Well, those of you who have shell users. This is useful for system admins who want to send mass messages to the people who are currently logged in. For example, maybe you want to message folks to let them know that you’ll be doing routine maintenance and rebooting the system at a specific time.

While this is a bit archaic, it’s still useful under some circumstances.

Why do I include it if it’s so archaic and has limited use?

Well, because I can. You never know when someone doesn’t know something and will hit up their favorite search engine to learn something. I care that each article teaches you something, even if that something isn’t all that grandiose. 

Plus, it’s nice to have an easy article now and then. This is going to be a pretty easy article! There are just a couple of tips that I have for folks and that’s the end of it.

Send A Message To Logged In Users:

You’ll need an open terminal if the opening wasn’t descriptive enough. After all, we’re sending messages to users who are logged in with the terminal. So, open said terminal. Most often, you can press CTRL + ALT + T and your default terminal should open.

With your terminal open, you can be reasonably sure that the wall command is available. Run this command to be certain that the wall command is available:

You can then check the man page to ensure that this is the correct tool for the job. As you’ll see, if you run man wall, this is the tool for the job:

wall – write a message to all users

See? It is the right tool for the job. The syntax is even remarkably simple:

Or, if you do this often and want consistency:

So, you can try something like:

Or, if you do this often, you can make a .txt file with your message and just reference that file in the wall command. That’d look like the above example.

See? That’s it. That’s all you need to know to send a message to logged in users. If you’re new to your admin job or maybe have started running a public-access shell, you’re now able to send those messages to your users.

Closure:

I figured it was a good day for a nice easy article. They can’t all be complicated, because not everything is complicated. Sometimes, it doesn’t take 1000+ words to describe a task. I could probably bloviate and digress, but that’d just make the article longer with no real value.

As much as it might seem otherwise, I value your time. I try to remain on topic and I try to include no more than the information you need – with just a bit of digression in the intro. I figure most of you skip the intro anyhow!

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