Clear Cache, Buffer, And Swap Space

Many Windows users will want to clear cache, buffer, and swap space. It’s a holdover from their Windows days, and it’s possible to do those things with Linux. This article will explain how to clear your RAM cache, buffer, and swap space.

One of the first questions we should be asking is, “Will this help?” The answer is, like many things, “Well, it depends…” It depends on a number of variables, like how much RAM you have, and how aggressively the kernel is paging, or what your swap preferences are. For example, quite a few people have decided to forgo swap entirely. Cleaning swap space is not going to help them out one bit.

The second question should be, “What exactly are we cleaning, anyhow?” The answer to that is a bit clearer, thankfully. The things we’ll be dealing with are:

  1. PageCache/Page Cache; The Linux kernel stores data in unused sections of memory in case it needs it again. Since kernel 2.2, Buffer Cache and Page Cache have been combined and there’s just PageCache.
  2. Dentries; They’re “the in-memory representation of a directory entry” and include things like meta data.
  3. Inodes; Meta data about all the files on your mounted file systems.

Those things build up in RAM and they can be cleaned out. The Linux kernel is really good at managing these things and unused RAM is wasted RAM (within reasonable limitations), but they can be cleaned out and this article explains how.

Clear Cache, Buffer, And Swap Space:

This article requires an open terminal. To open one, you can just use your keyboard – press CTRL + ALT + T and your default terminal should open right up!

I took the time to explain what you’ll be cleaning in the article’s opening. That’ll make this section easier!

To clear PageCache by itself:

Or you can clear Dentries and Inodes:

Or even clear PageCache, Dentries, and Inodes at once:

NOTE: These work as advertised. Before you run one of these commands, run free -m before and after running the command. By doing that, you can see what the results are and what the results will probably look like in the future.

Frankly, I’d only see this as a very valuable tool if you have little RAM, or want to free up some resources before opening something that is resource-intensive. Other than that, just let Linux do its job – managing cache, memory, and other resources.

But, if you’re a Windows user and want the comfort of some familiarity, this won’t harm anything and could provide the very slightest of benefit. You could even alias it to an easier-to-type command and run it as often as you want. It’s your computer, you do what you want with it!

Closure:

There it is, another article! We’re rapidly approaching the 6 month mark and so far things have gone well. This time, you get an article letting you know how to clear cache, buffer, and swap. Who knows what the next article will be?

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.

Linux Installation USB Media Using Windows

This is a guest article by @captain-sensible, about Linux installation – specifically creating USB media using Windows. I trust him on this, and don’t feel qualified to do much in the way of editing as I know next to nothing about Windows. So, without further ado:

Preamble:

If you already have Linux as your OS, then an article about how to get a Linux .iso onto a USB stick is probably redundant. The other thing I can deduce is that if you want to have a go at trying to install Linux, that would mean you probably don’t have Linux OS nor access to programs that run on Linux.

You might think an article involving Windows is not a good fit for Linux tips? Well I disagree the tip to put it succinctly is this – “Linux and how to get it” I.e. you want Linux but you don’t have it, and so the article is about getting it using the only tool you probably have at your disposal, which is Windows. (That’s assuming you don’t have any avisée friends using Linux)

Therefore, I am going to go through how to use Windows and software tools to get a Linux OS iso file onto a USB from which you can boot. Maybe in part 2 I could mention use of ventoy on a Linux box and persistence for a live Linux OS on a usb .

Now there are a couple of tools you can try including:

https://www.balena.io/etcher/
https://rufus.ie/

But here we will have a look at Ventoy. Ventoy has a couple of useful features – you can put several Linux ISOs onto the same stick and boot from any of them via the Ventoy boot splash menu. Also via one of the Ventoy tools called CreatePersistentImg a file is created, inside the same directory that the script is run and can be configured to be used on the formatted stick with the ISOs so that the live OS can install software.

Our Agenda will be:

  • Download a Linux .iso file
  • Download Ventoy
  • use Ventoy to format a USB stick we have
  • Drag .iso file onto ventoy formated stick
  • Boot from USB stick

Create USB Media Using Windows:

Normally I use Linux with ventoy; for this exercise using Windows10, I downloaded linuxmint-20.2-cinnamon-64bit.iso from University of Kent Mirror.

See Linix Mint Cinnamon Mirrors

Now with a download you need to check the integrity of the download. You can get the sha256 sum from:

https://ftp.heanet.ie/mirrors/linuxmint.com/stable/20.2/sha256sum.txt

And the gpg from:

https://ftp.heanet.ie/mirrors/linuxmint.com/stable/20.2/sha256sum.txt.gpg

Instructions for verifying your download can be found at:

https://linuxmint-installation-guide.readthedocs.io/en/latest/verify.html

Next we need to download Ventoy:

Go to this URL:

https://sourceforge.net/projects/ventoy.mirror/files/v1.0.52/

Shimmy down to ventoy-1.0.52-windows.zip and mouse left click to download it to your PC. Right click and choose “extract”. You will probably get something like select a destination – go for Desktop if you can; at least you can find it easily.

Anyway that will unzip the zip file. I found once unzipped that the directory I wanted was inside another directory called ventoy-1.0.52-windows, the directory and its contents you want is the one labelled ventoy-1.0.52.

See image below:

That’s the one that contains the tools you need including Ventoy2Disk, an executable Windows file. Drag that directory from inside the outer directory to your desktop.

To fire up Ventoy, go inside the ventoy-1.0.52 directory and mouse left click twice on Ventoy2Disk. You should then see a dialogue box (see image below). Now from the image it tells you that it thinks Device E: SanDisk is the USB stick to be formatted. The main point being you need to insert a preferably virgin USB stick, a USB thumbdrive with nothing on it, into your PC before Ventoy2Disk can work on anything.

Now its always best to double check things. One way of doing that is to fire up a disk utility and see what’s listed. You will use common sense as well – A 16GB storage device is unlikely to be your PC internal hard drive. Lets have a look anyway.

One way of confirming is to use Disk management. To fire that up hit the key with Windows Icon on it and R, that should bring a dialogue box up with a text box . Into the text box type Diskmgmt.msc; you should then see Disk Management and entries – see image left.

Disk management and venoy dialogue

I think I can conclude with Ventoy that Spare E is the USB I want to use. One reason is that I formatted it and labelled it using GParted. So next with USB attached to PC, left click on the install button of the Ventoy dialogue box. Now when its finished, pull the USB out and re-insert it , that’s to make sure the PC is correctly recognizing, the USB which will now have a label – ventoy.

Drag iso from download location onto ventoy usb

If you look at the above image, a window is open with location of the ISO file and the other Window on the right is the newly labelled USB stick called ventoy opened. All you have to do is use your mouse and literally drag holding down left, on the mouse from the left window onto the right window. You might have to fiddle with Windows, I know I did with Windows 10 on the laptop I was using.

Once that’s been done its a case of now shutting down Windows and from a cold boot hit the key which will give you boot options. The laptop I was doing the operation was a H.P stream so for that laptop F9 is the boot option key and F10 is the bios. You have to hit the keys almost immediately after powering up.

I had a couple of glitches on powering up, getting the boot option and booting from the USB I got “image not authenticated “now what came to mind was checking the integrity of the download. No that wasn’t it.

boot glitch

One issue was expected in disabling secure boot and enabling legacy boot; the other one wasn’t. What is was is that although I had edited the BIOS, there was a “Operating System Boot Mode Change” notification.

I did as requested entered the number quoted, hit Enter (return key) and after that I was Ok. I then got Mint booted live! Finally – Windows doesn’t like to let go easily.

Moving On:

Now when you get to the stage of getting a Linux OS up live from a USB here are a view bits of advice:

On the Desktop of your live Linux OS you will see an icon saying install Linux, don’t rush in and do that. Play around for a week with the live OS, get to know it and try of launching a shell (terminal window). Learn to use, at least launch and have a look at tools such as GParted and screenshot. You can use apt-get or apt from a terminal to search for that.

Those sort of tools and your ability to use them will come in extremely handy if you have any issues and need help from a Linux forum. Users will want to see your partitions (use gParted) and see what some things look like (use screenshot) they will probably also want to see some output of commands on the shell (your ability to use basic commands needed).

The live Linux OS you have doesn’t have persistence, you can play with installing software and it should install but only in RAM. You can achieve persistence with the Ventoy approach, but thats perhaps for another time.

Closure:

There you have it, an article about creating Linux installation USB media using Windows. This one was written by a guest, now a registered user and author. So, kudos to them for stepping up and contributing!

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 About A Brief Overview Of The Cat Command?

This is just a brief overview of the cat command. There are all sorts of ways to use the cat command, and I’m just going to cover some of the most common ways – the ways you’re most likely to use the command in day to day activities.

You’ll find ‘cat’ popping up in various tutorials and may find it being used for all sorts of things. As a command, it has existed since the earliest days of Unix (about 50 years ago, as of the time of this writing) and it gets used still today. If you check the man page, you’ll see that cat describes itself as:

cat – concatenate files and print on the standard output

But I find the Wikipedia description to be even better, at least more descriptive:

cat is a standard Unix utility that reads files sequentially, writing them to standard output.

If you’re curious, ‘concatenate’ just means linking stuff together in a chain or series – but ‘cat’ is more frequently used just to read the contents of a file by writing them to the standard output.

You can use this output in a number of ways, though this article aims to be just a fairly brief article, just an overview of the cat command. I haven’t written it yet, but i expect it to be reasonably brief!

An Overview Of The Cat Command:

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.

Next, I want you to run the following commands:

That just downloads a text file with some random numbers in it. It’s harmless. Now, let’s view it in the terminal:

If you don’t want to display all the results at once, just try piping it to the ‘less’ command. You can do that because cat handily outputs to the standard output. It’s just:

Alright, that was fun! Let’s try something nifty.

That will take the output of the cat command and add it to a document that you just created at the same time. So, if you want to see your handiwork, just try this command:

You’ll see the contents of ‘rnd-num.txt’ are now in the new file. If you use > it overwrites the contents of the file, but if you use >> it appends the content to the new file. To test that again, try this:

Now, if you cat the ‘new-file.txt’ you’ll see that it has twice as many lines as it did have. If you want to see it for certain, cat will helpfully add line numbers! Try this:

Then run (and it should show 100 lines):

Or, for even more fun, you can actually combine those (or just show the output from multiple files without the -n flag) with this:

Anyhow, those are a few examples as an overview of the cat command. Use the man cat command to learn more about it.

Closure:

And there’s another article! Thanks for reading! For a bonus, you can also use cat like touch and create a new file, like so:

When you use ls you’ll see the new file has been created called ‘example.txt’. Tada! Really, read the man page and learn all the wonderful things you can do with the cat command. This has been just a brief overview of the cat command, and there’s so many more nifty things that can be done.

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 Count The Running Processes In Linux

This article will show you how to count the running processes on your Linux system. Like many articles, it will show you how to use some tools that you may not yet know about.

The tools in question will be ‘ps‘ and ‘wc‘. The ‘ps’ command reports the current processes and the ‘wc’ stands for word count and has uses beyond just counting individual words, as this article will show you.

If you’re curious, the man page describes them as:

ps – report a snapshot of the current processes.

And:

wc – print newline, word, and byte counts for each file

We will be using both of these tools, not just to just count the running processes, but also to expose you to these tools. After all, it’s really not all that important to count the running processes. I suppose if you have resource constraints, but it’s not so important the number of running processes – but how computationally expensive those processes are.

So, this should actually be a pretty short article and it’s definitely in the beginner territory. If you’re an advanced user, it’s likely that you’ll have at least some familiarity with these tools. Even if you’re an expert, have some fun and read on!

Count The Running Processes:

Like many other articles on this site, we start with an open terminal. You can open your terminal with your keyboard – just press CTRL + ALT + T and your default terminal should open.

With the terminal now open, we’ll start with the ‘ps’ command. Running just ‘ps’ is pretty useless, so be sure to check man ps for more information. Instead, we’ll run it with the -e flag to show every running process.

Tada! That shows you every running process. Now, let’s see the same command with the -U flag. You can’t just use the -U flag by itself, it requires a username. So, try this to show all the processes being run by a specific user:

Where you see <user>, put your username. In my case, the command would look like ps -U kgiii – and don’t forget that it is case sensitive and lowercase letters are all you can use in your username. Anyhow, that command will show the running processes owned by the user ‘kgiii’.

So, all that is well and good. How about we now count them? To do that, you just need to add a pipe and wc -l. We’ve used a pipe before, and the pipe is one of the greatest concepts in Linux – as it allows you to take the output from one command and pipe it into a new command.

Using the information above, we would then try:

And to count the processes from a specific user, you’d just use:

An example output of the latter would look something like this:

A count of processes owned by user 'kgiii'.
Counting the processes owned by user ‘kgiii’. A nice even 200, strangely enough.

That’s about it, really. You can check the man pages for both ‘ps’ and ‘wc’ to learn more about them, but this would be how I’d count the running processes on my Linux boxes. 

Closure:

There you have it, another article – this one telling how to count the running processes. Hopefully, we all learned a little something today and hopefully we’ll all learn a little something new in two days – which is when the next article should come out.

We’re approaching the halfway point in this year-long project. It has been good fun and I’ve learned a great deal. If I had to speculate, I would guess that this project will keep going beyond the one year mark, though maybe with a more lenient publishing schedule!

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 Play Around With The ‘MV’ Command

Today, we’re going to play with the ‘mv’ command, just as the headline implies. It’s a pretty easy command for anything you’re likely to do with it, and it’s a great way to accomplish some pretty neat things in the terminal.

So, let’s start with the ‘mv command. Right away, when we check the man page, it shows you one of its greatest features. It defines itself as:

mv – move (rename) files

And right away you see that it does more than just move files. It also seems to be a command that newer folks don’t use. Maybe they’re afraid of it? Maybe it just doesn’t get enough love? I dunno, but I know it’s a pretty great command. This article is gonna cover it.

Let’s mix things up a little! Why don’t you open your terminal and we’ll start from the same page. Enter the following commands into your terminal, one after the other, pressing enter between each one.

Now, assuming I’ve done that properly and you’ve followed along, you should have made some files, a couple of directories, and your ‘pwd‘ (print working directory) is ~/Documents/tmp.

See? Now we’re all on the same page, and this is a fine time to start an article about the ‘mv’ command!

Play With The ‘MV’ Command:

So, for once, I don’t have to start this section by telling you how to open your terminal! You should have it open from the preparation we did in the intro! That’ll save some time…

So, with that terminal open, I want you to enter the following:

That should move the ‘file1.txt’ to the test directory. If you want to actually verify this, just go like:

Which should show you that the file has in fact been moved. Let’s go back to that same tmp directory and verify that it’s no longer there.

And you’ll see that file1.txt is no longer there in the tmp directory. And, seeing as you’re back in the right directory, let’s rename a file using the ‘mv’ command. Try this:

This will have renamed the file2.txt to changed.txt and you can once again verify that the former has been renamed to the new filename changed with the ls command.

Finally, with one more trick up its sleeve, you can both change the name and move the file at the same time. To do so, you’d just go with:

If you then run ls in both the pwd and test directory, you’ll see all the changes have been made, exactly as intended. If you need to, open your graphical file manager and verify it visually, but you can just as easily use the ls command and verify it all.

For fun, if you want to delete all those, you can move to the ~/Documents directory (cd .. or cd ../..) and use this command:

That’ll clean up any sign that we’d been there and done this exercise. There’s more to the ‘mv’ command and, as always, be sure to check the man page for more usage instructions (to learn things like the -f switch). But, these are the most common ways you’ll use the ‘mv’ command and I wanted you to have a basic familiarity with it.

Closure:

And there you have it… It’s something a little different, as I felt it important that we start from the same place. I also figured I’d try a little bit of a different writing style for this one. If I can’t have fun, why do it? Either way, it’s yet another article. It’s one step closer to the year-long commitment I’ve made. (It’s gonna be a long year.)

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.

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