Remove A Swap File

In today’s article, we’re going to learn how to remove a swap file. This isn’t something I recommend, for reasons I’ll explain, but I have no ethical qualms about telling you how to do so. After all, it’s your computer. You get to decide what it does!

There are some folks who will tell you that if you have enough RAM you don’t need swap. Well, I am not one of those people. I tend to have swap enabled regardless of how much RAM I have. I have a good reason and I’ll explain it to you as best as I can. I mean, the actual inner workings of the kernel are above my head, but I’ll explain it – or let other people explain it.

See, contrary to popular opinion, swap isn’t just a place the kernel sticks stuff when you’re running low on RAM. For example, check out the picture below:

swap in use with plenty of free RAM
As you can see, swap is used even with plenty of free RAM.

Here’s more information about the free command.

Now, do me a favor and go Google Linux and swap. You’ll find plenty of pages that briefly have this to say (and barely this to say):

Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full …

                                                                                                        That’s from MIT!

That’s only about half the story… There’s more to it, and that is kinda important.

Some More About Swap:

So, is it really that simple? Of course it isn’t! If it was really that simple, the intro to this would have been so much easier to write. No, it’s slightly more, a bit more, complicated than that. See, let’s quote a more thorough (and accurate) Linux.com:

Swapping is necessary for two important reasons. First, when the system requires more memory than is physically available, the kernel swaps out less used pages and gives memory to the current application (process) that needs the memory immediately. 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.

                                                                                                     –Emphasis Mine.

What can we take from that? Well, it’s not just a place where the kernel stuffs things when there’s no RAM left – it’s also a place the kernel sticks things to avoid wasting RAM. This is very different than swap is just a place where the kernel stuffs things when RAM is low. It avoids using some RAM that’s best used elsewhere. That seems kinda valuable and important to me. Again, the inner workings of the kernel are pretty much witchcraft to me, but swap seems like a good thing to me.

The kernel is pretty smart about this, from what I’ve observed. It’s good at its job. It’s better at its job than you are. It is better at its job than I am. I highly encourage you to use swap, saving your RAM for more useful things. With disk space as large as it is, you’re not going to miss a couple of gigabytes. Let the kernel do its job, managing RAM as best as it can. They’ve put thousands of hours into making the kernel smartly deal with RAM, there’s no reason to hobble it.

Of course, ain’t nobody gonna listen to me… So, with that said, I might just as well go ahead and tell you how to remove a swap file… You’re gonna do what you want anyhow!

Remove A Swap File:

This article requires an open terminal, like many other articles on this site. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

The first thing we’re going to do is verify that you actually have a swap file…

If that mentions a swap file, only calling it a ‘swapfile’ (a single word), then your next step is to turn your swap off.

Now, for your next step you will want to remove the swap information from fstab, so let’s go like this to do that:

Find the line that starts with /swapfile and delete the entire line. All of it. Leave nothing behind. If you screw this up, your next boot may be an interesting exercise. The line is probably longer than it looks unless you’re using a terminal in full screen! Be sure to remove all of it. It should end with a 0, actually a 0 and then a tab and another 0.

Be doubly sure to remove the full line and then save your work. Then save it with nano. To do that, just press CTRL + X, then Y, and then ENTER. That’ll save it.

Finally, remove the swap file itself. That one is nice and easy, you just:

That should do it! If you’ve realized you’ve made a mistake and want to have a swap file, you can always add a swap file. (I’m pretty sure it should be ‘swapfile’, but the rest of the ‘net calls it ‘swap file’, so I’m going with the majority – even though the majority don’t even know what the damned thing does!)

Closure:

There you have it. You now know how to remove a swap file. If that’s what you want to do, you go right ahead and do it. Truth be told, assuming you’ve got enough RAM, it won’t necessarily break anything. You might not even notice it is gone. Still, I figure it’s better safe than sorry – and who am I to judge what the kernel wants?

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 own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Let’s Shred A Partition

In today’s article, we’re going to shred a partition. What does that mean? It means we’re going to erase the data in a manner that makes it difficult for that data to be recovered. Notice that I didn’t say ‘impossible’? That’s because they’ve got some pretty sweet forensic tools out there and who knows what they can recover.

This will keep your deleted data safe from a common thief or dumpster diver. It’s also not a bad idea to just destroy the drive, perhaps after shredding it, just to be sure. If you’re the enemy of a powerful government, you probably shouldn’t keep data on hard drives unless you’ve secured them very well! This may not help those sorts of people.

The tool we’ll be using is actually called ‘shred’. It’s possibly installed by default, but it’ll be in your default repositories. The command defines itself as:

shred – overwrite a file to hide its contents, and optionally delete it

It further describes itself as:

Overwrite the specified FILE(s) repeatedly, in order to make it harder for even very expensive hardware probing to recover the data.

This is actually a pretty easy article and won’t take much time to go over. There’s just a couple of commands I wanted to cover, and we’ll  just showing you how to shred a partition. So, ‘snot all that complicated, nor all that involved. On with the show!

Shred A Partition:

Like many other articles on this site, we’re gonna need an open terminal. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

First, let’s make sure you have shred installed. Enter this command:

If you don’t have shred installed, you’ll need to install it using your package manager. If you are using apt, then it’d look like:

Once installed, you need to know which partition you want to shred. For that, you’ll possibly need the following:

Once you have identified the partition, such as ‘sdb2’, you can shred the partition. To do that, try this command:

We use the -v for verbose, so it shows us the progress. This command will do the default. It will overwrite the partition three times. You can change that value easily enough. To do so, use a command similar to:

The -n lets you pick the number of times it will shred the partition, that is overwrite it with data, and you can pick any number you want. So, change the ’10’ to whatever you want, but be aware that it can take quite a while.

That’s it, really. There’s more that you can do with shred, so check the man page. I’m only covering how to shred a partition in this article.

Closure:

There you have it, another article. This one tells you how to shred a partition. If that’s something you need to do, you now know how to do it. As I mentioned in the first section of this article, it’s not very complicated. It will take some time, so be sure to use the -v option and keep track of what’s going on.

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 own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

A Couple of Ways To Resize Images With ImageMagick

In today’s article, we’re going to go over a couple of ways to resize images with ImageMagick. It’s a useful skill to have if you’re into sharing images or the likes. This will actually be pretty quick and easy. I won’t take much of your time today but it’ll be longer than some other articles – but it really should be a quick read for you today.

It’s nice to not put full resolution pictures online – unless there’s a reason for the higher resolution. So, it’s a bit of a politeness to resize your images. I try to be considerate, ’cause I know what it’s like to have limited bandwidth. You people who started off in life with things like 100 GB fiber have no idea the pain we went through to get here! Alas, that whining is perhaps subject to another article, though probably not really a suitable article for this site. There are people who still use slow connections, and metered connections are entirely too popular.

So, what is ImageMagick? It describes itself as:

ImageMagick – is a free software suite for the creation, modification
and display of bitmap images.

ImageMagick is actually quite a useful application for quickly and easily manipulating images in the terminal. ImageMagick is so robust that trying to cover all of it in a single article would be foolish. I simply couldn’t do it within the bounds of a single article.

That’s why we’ll just be examining a couple of quick ways to resize images with ImageMagick. We couldn’t possibly cover it all today. If you want to see what all the options are, I’d recommend checking the man pages – and reading other tutorials that cover the things you’d like to do.

With that said and done, let’s resize some images with ImageMagick!

Resize Images With ImageMagick:

This article requires an open terminal, like many other articles on this site. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

The first thing we’re going to need to do is make sure you have ImageMagick installed. So, let’s install it. The command below is for those who use apt, but you can easily change it to your own package manager. I’m 99% certain that ImageMagick will be in your default repositories! It’s a pretty widely used application! The command for those of us who are apt-using people is simply:

Follow any on-screen prompts to install it, else it’ll tell you that it is already installed. ImageMagick appears to be installed by default on a number of distros, but it’s easy enough to install. You can actually just add a -y to it and skip some of the prompts:

Of course, you’ll still need to enter your password. Well, if you really want to live on the edge, you can enable passwordless sudo easily enough. I don’t really suggest that, but I do tell you how to do it. ‘Snot something for the faint of  heart.

Ah well… Onto the meat of the article!

Resize By Resolution:

Now that you have ImageMagick installed, let’s try resizing something. What we’re going to do first is resize it by way of the resolution. That is, we will resize it by declaring the new height and length. To do so, you’d use a command like:

For example, you might try something like this:

See? Pretty easy. I told you this wouldn’t be too hard – nor will this article be all that long. Well, it might be a bit longer than some, but I won’t let it be too long. I know my reader’s attention span! You should make sure to use the same base resolution. If the image is 16:9, your resized image should retain that aspect ratio. Otherwise, your images may appear warped and ugly.

I should probably mention that it’s possible to make images larger with this command. However, when you make an image larger you lose fidelity. Making an image too large is going to result in an ugly image. It’s not like the television where you can just keep zooming in and enhancing. Ones and zeros don’t work like that.

Resize By Percentage:

This is my favorite way to resize images with ImageMagick, unless I have a specific reason to resize images by resolution. In this case, you just declare a percentage of the original and ImageMagick does the rest. It’s really a very easy command. It looks a little like this:

If you want, here’s an example of how you can use that command to resize images by percentage with ImageMagick:

That command will make ImageMagick output a file that’s 50% smaller than the original image. Not only will this be a smaller image visually, it will have a smaller file size. Because of the way images work, this doesn’t mean the new file size, size on disk, will be reduced by 50%. It just means you’ve reduced the image’s dimensions by 50%. The size on disk will also be lower, but it’s not directly proportionate. 

Like above, where  you resize the image by resolution, you can use this to make images larger. The same caveats exist that existed above. That is making an image too large means it results in a poor quality image. As you can guess, making images larger isn’t always a good idea, but it’s generally fine if the operation is making the images smaller.

Closure:

And there you have it. You have another article! This time, we’ve covered how to resize images with ImageMagick. I think that’s a useful skill to have and it’s a quick/easy thing to learn. Of course, you can always check man imagemagick to check the man page. That man page will be enlightening, I suspect.

I’ve changed the format a bit for this article (though I’ve used it before), and made it a bit longer than the recent articles. If you have an opinion on the matter, please feel free to leave a comment. The more I know about your wants, the more I can tailor the content. The more I can tailor the content, the better you’ll enjoy the content. To do this, I need to know your thoughts on the matter. Speak up!

So, do you enjoy the longer articles? Do you enjoy the shorter articles? Do you appreciate a mix of them, and each article only being as long as it really needs to be? I normally try to keep all my articles friendly, informative,  and fairly strictly informal. Lately they’ve been pretty  short, but I can be more verbose, as many of you will have witnessed.

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 own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

How To: Search With apt

Today we’ll learn how to search with apt. There are any number of reasons why you’d want to do this. You can use this to find applications by name or subject. Maybe you want to find files that meet a certain criteria? It could be that you’ve forgotten the name of the application you’re thinking of? Perhaps you want to know if an application is available in the repositories before you go seeking it elsewhere?

There are all sorts of reasons, including those, why you might want to search with apt. Obviously, this requires an operating system that uses apt, so that limits you to things like Debian, Ubuntu, official Ubuntu flavors, Linux Mint, etc… So, well, it’s a pretty sizable number of distros where this will work.

This will be a pretty simple article. It will also be pretty brief. I’ve likely mentioned searching in another apt article, but it’s important that we cover it. Alas, I’m running out of things that make for longer articles (in the notes I’m working from), so this is just another article where I’m trying to make you aware that certain tools exist.

This should absolutely be a short and easy to understand article. In some recent commentary, I realized that what’s ‘simple’ to me is something that someone else has been dealing with for the past year. Even my easier articles have the chance to help people figure out their Linux problems. Good… It makes me feel better when I write an ‘easy’ article.

So, with all that said… Let’s learn how to:

Search With apt:

This article pretty much requires an open terminal, like oh so many other articles on this site. If you don’t know how to open the terminal, and you should by now – if you’ve been following along long enough, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

Now, it should go without saying, apt is how you interact with your package manager. It’s how you install, uninstall, or otherwise manage your software in the terminal. You could insist on using a GUI to install software, in which case this won’t be of much interest to you, or you could just do it all in the terminal. Either way, if you are using a different package manager then this will be of no value to you.

Me? I prefer to do this sort of stuff in the terminal because I find it easier and faster. I’ve already got a terminal open anyhow, so I might as well use it.

Anyhow, with your terminal open, go ahead and type:

For example:

Seriously, if you’ve never used the search function, go ahead and try the above command. You might be surprised by what you find.

Now, if you’re trying to narrow it down some, you can use the –names-only flag. Which isn’t as accurate as it could be. For example, try:

But, as near as I can tell, that’s searching not just the names but also searching the one-liner description. Like, if you run the above command you’ll also see ‘terminator’, which is definitely not ‘terminal’.

However ‘terminator’ includes ‘terminal’ in the description. So, I’m not sure where that’s going with that and the man pages weren’t all that helpful. You can also use RegEx (Regular Expressions, for the uninitiated). For example,  you can run:

This, of course, only works if you have Google’s Chrome repositories enabled. Otherwise, pick something else to test this with. Or, just trust me when I say RegEx works, which the man page will confirm.

Anyhow, our example command from above would (on this computer) would have an output that looks like this:

Which, as you can see, means I have multiple versions of Chrome available. So, that’s something positive in my life! But, the point is, I did a search with apt and came away with the information I wanted. I’d normally send you to the application’s man page, but in that probably won’t make it all that much clearer. 

Closure:

Yeah, that’s it. You can now search with apt and find what you’re looking for. Use some of your own search terms, like apt-cache search image editor, and see what sorta results you get. It’s not the most refined, but it’s an effective way to search with apt.

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 own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Let’s Talk About Using dos2unix

Today, we’re going to talk about using dos2unix, a tool for converting Windows text files to Unix (Linux) formatted text files. The command isn’t very difficult to use, so this article is more about making you aware of the existence and purpose of said dos2unix. It should be a remarkably short article.

First, we have to go back in time…

Once upon a time, when you reached the end of the line with text, you had to instruct the hardware to start a new line. These were the old days of things like teletype machines and dumb terminals. They needed to be told when to begin a new line.

Well, that still exists in software today. The thing is, if a file was created on Windows it will have two characters denoting when a new line should begin while a file created on Linux will only have one character indicating when a new line should begin. Yay for compatibility issues!

Anyhow… This is why you will sometimes get errors with text files. For example, writing a shell script on Windows and then trying to use it on Linux may result in end of line errors. Windows uses CR (Carriage Return) and LF (Line Feed, you may know it as /n) while Linux (and Unix) just uses LF. This, of course, can cause some confusion for the operating system.

This is where dos2unix comes into play. This is why you’re getting an article about using dos2unix… So, with that in mind…

Using dos2unix:

This article requires an open terminal, like oh so many other articles. If you don’t know how to open the terminal, just press CTRL + ALT + T and your default terminal should open. Tada!

Now, you’ll need to install dos2unix. It probably isn’t installed by default. Just use your package manager’s standard install command and I’m like 99% certain it’s a package available to you by default. For example, in Debian, Ubuntu, and Ubuntu derivatives and flavors, it’s just a simple apt command:

Once you have dos2unix installed, you can convert Windows-created text files to Unix (and thus Linux) formatted text files by fixing the way they end a line and start a new line. That’s really easy. It’s just:

Yup…

Well, I suppose you could also do /path/to/filename.txt if you needed, or you can just navigate to the directory and use the command above. It really is that easy.

There’s more to the dos2unix application, but that’s about all you’re really going to need to know under normal circumstances. It really is that simple. Do check the man page (man dos2unix) for other options, but you’ll see that’s about all you’re gonna need.

Closure:

Like I said, this article is really about making you aware of the problem and solution, so that you can start using dos2unix if and when you need it. It turns out that dos2unix is more than just a contributing forum member on Linux.org, it’s actually a useful application for dealing with Windows files on a Linux box!

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 own 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.