Let’s Play Around With ‘apt-cache’

Today, we’re going to learn about apt-cache. Obviously, this information is only useful for distros that use the apt package manager. You’ll find that apt, and apt-cache, are package management tools – useful for managing (installing, removing, and updating) the software on your computer.

To know about apt-cache, we should probably know about apt. I think the man page describes apt well enough with this:

apt provides a high-level commandline interface for the package management system.

And apt-cache defines itself as:

apt-cache – query the APT cache

While it further describes it as:

apt-cache performs a variety of operations on APT’s package cache.

As you can see, they’re necessary and valuable tools for the management of software on your Linux box. Not all distros use apt, but it’s generally used by the distros in the Debian family. Those are distros like Ubuntu, the official Ubuntu flavors like Lubuntu, Kubuntu, and Ubuntu Mate, as well as distros like Linux Mint. 

So, it’s used by quite a few distros and, importantly, many of those distros are the favorites for people who use Linux on the desktop. I’ll also note that apt works equally fine in a server environment, without a desktop. It’s widely used, widely supported, and easy to find assistance when you have questions.

Today, we’ll just be covering ‘apt-cache’ and some of the basic usage. It’s not a very deep article, nor does it need to be. While there are a ton of apt-cache options, chances are that you’ll only need to use a few of them. So, this shouldn’t take too long out of your day, or will make a good resource when you need to remember something.

Using apt-cache:

This article requires an open terminal. Just press CTRL + ALT + T and your default terminal should open.

For this article, our example will be inxi. We’ll assume you’ve already installed it, or are already familiar with it. If you don’t have it installed, now would be a good time to do so – as it’s a very handy tool. Where you see ‘inxi’ you can use any other package name you want. 

An easy command, if you want to display a bunch of generic information about a package, is the following:

That will show you a bunch of information about a package, installed or not. It requires the complete package name. In the next command, that’s not really required.

With the search flag, you could type in ‘inx’ and it will find inxi, among other things. You can use that command with the ‘–full’ switch, and get a ton of useful information:

You don’t even have to use an application name with the search – you can search for keywords and find applications that way! If you wanted a text editor, you can use:

You might be surprised at the number of results you’ll get with that command. There’s probably some text editors you’ve never heard of before, and they’re right there among those results! Installing them is just a command away!

We can also check the policy, showing things such as which version is installed, which version is available, and the repository name. It’s just as easy as the rest.

The output of that command is pretty handy. It’s a short output that tells you which version you have and which version you have installed. It’ll also tell you which repositories hold the software, often more than one, and what the priorities are for those repos.

Bonus apt-cache Features:

Among these great features, you can easily see both the dependencies and the reverse dependencies. Dependencies are the extra software that needs to be installed for the package in question to function and reverse dependencies are those packages that require the installation of the named package to be fully functional.

To find the dependencies:

The reverse dependencies:

There you have it! Those are the most common ways you’re going to use apt-cache. If you want to know more, you can always check the man page with man apt-cache. Dependencies, both regular and reverse, are probably worthy of their own article at some point. Normally, your package manager will deal with those, but you sometimes come across situations where you need to resolve dependencies on your own.

Closure:

And, there’s one bonus round! There’s pretty much no good reason to run this, other than curiosity, but you can actually get some pretty cool stats about how many packages are available, how many are real packages, how many are virtual packages, and things like that. It’s a pretty simple command with a lot of output.

See? Another lovely way to use the terminal to gather information. Personally, I do pretty much all my software management in the terminal. I just find it easier, more informative, and faster. I’ve done it for so long that it’s legitimately faster for me to use the terminal than it is for me to do so in the GUI.

Anyhow, thanks for reading. This is yet another article in a growing list of articles! We’re well past the halfway point in the year-long project and so far we’ve yet to miss a single publication date!

It’s going to feel good to finally say that my obligations are over – and then to probably keep writing just to keep getting more and more of this stuff online on my own site. ‘Cause that’s the kind of thing I do… In theory, I’m retired. However, I keep obligating myself to do more and more things. Ah well… This site is at least productive and, judging by the numbers, beneficial to the community.

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 Determine The Number of RAM Slots Without Opening The Case

Today’s article is going to show you how to determine the number of RAM slots without actually opening up your case. It’s actually a pretty easy task, consisting of just a single command. 

But, wait! There’s more! You may want to know than how many RAM slots you have, you may want to know a lot more about the RAM you have already installed, how many slots are filled, if your RAM has ECC (error correction), the speed, the quantity of RAM per stick, etc…

Well, you can do all that and you can do it all with just a single command. The command in question is dmidecode. While dmidecode isn’t guaranteed to be 100% accurate, it’s usually pretty close. It pulls its data from tables in the DMI (SMBIOS) and presents them to you. Hardware manufacturers aren’t always as nice to Linux users as they could be, so there’s some risk of bad information – or wrongly interpreted information.

While dmidecode has partially been covered previously, it defines itself as:

dmidecode – DMI table decoder

And dmidecode is a pretty handy tool. In a previous article we used it with some success, and we’ll be using it again today, this time to determine the number of RAM slots available to you. On a scale of 1 to 10, I’d say this is a solid 2 – meaning even a rank beginner can follow along.

Determine The Number of RAM Slots:

This article requires 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.

With your terminal open, enter the following command:

The line that is important is, “Number of Devices”. On my laptop, the output looks like this:

using dmidecode to determine the number of RAM slots available
The answer is two. Two slots. Ah ah ah ah! Oh how I love to count things!

So, from that, we can determine the number of RAM slots is equal to two. If you want, you can then scroll down and it will show you what RAM is installed. You can see if you have the same number of devices as you have slots. You can even see the size, number of slots, location, vendor. You can use it to learn a great deal about your RAM. 

As I mentioned above, it’s not necessarily going to be 100% accurate. With bleeding edge of hardware, you’ll find it may be less accurate. If your hardware has been around for a bit, you can be pretty sure of the accuracy.

One of the things I notice is the “Maximum Capacity”. That may mean OEM suggested max capacity. I’ve sure seen more RAM than the claimed maximum. On the system, I see a max capacity of 8 GB of RAM. The box has 16 GB of RAM. I’ve seen it claim a maximum of 4 GB of RAM but had 16 GB of RAM in that box. 

Otherwise, it is usually pretty accurate. In the above, I suspect some OEMs are less than honest and would rather you not know that you can add as much RAM as you can. They’d rather you buy a more expensive device, so report the maximum RAM as less than it really supports. However, that’s just a guess and I have zero evidence to support it. It does seem pretty common, however.

Closure:

And there you have it, another article said and done. This one will help you determine the number of RAM slots that you have available. It’s a pretty easy article and a good tool to have in your toolbox. 

As you may have surmised, the antibiotics are kicking in. I’m feeling quite a bit better. Hopefully the articles reflect that. For the past few, I’ve kinda been phoning it in. My goal is to get ahead again. I can probably do that over the coming weekend. 

… Also, anyone reading this out of sequence probably has no idea what half of these closure comments are about. Then again, how many of those folks keep reading after the important bits? Probably not a whole lot. I could write darned near gibberish down here and nobody would be the wiser.

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.

Monitor Network Usage On A Per-Application Basis

Today’s article is going to tell you how to use Nethogs to monitor network usage on a per-application basis. It’s actually easier than one might think and we’ll even show you how to install Nethogs on a variety of distros.

Why would you want to monitor this? Well, you may want to know which applications are eating up most of your bandwidth. Not everyone has unlimited bandwidth after all. You might also be looking for rogue applications/malware that’s using up some of your bandwidth. There are all sorts of reasons to monitor your network usage at this level. Feel free to leave a comment telling us how you intend to use Nethogs.

As stated, we’ll be using Nethogs. The man page describes it as:

nethogs – Net top tool grouping bandwidth per process

I suppose that’s mostly useful to those who know what ‘top‘ is. (There’s a future article about top and htop, when I get to it.) But, Nethogs is like a system monitor, except it’s a network monitor with some visual similarity with top. (Yes, that’s an ugly, ugly sentence.)

We’ll be using ‘sudo’ for all of these commands. It’s possible to use Nethogs without sudo, but we won’t be covering that here. If that’s something you’re interested in doing, a search engine will help you get there.

Monitor Network Usage:

Nethogs is a terminal-based application. As such, you’ll need an open terminal. Just press CTRL + ALT + T and your default terminal emulator should open right up.

Once your terminal is open, you can go ahead and install Nethogs. Pick the command that works with your system’s package manager.

Debian/Ubuntu:

RHEL/CentOS (will need to enable EPEL):

Fedora:

Arch/Derivatives: 

Once you have Nethogs installed, you can check the help files. In this case, the help files are better than the man files (I think) so just enter the following into your terminal:

Now, to run Nethogs, we’ll use sudo and just run it in the terminal. Believe it or not, this mode is generally just fine for anything you’re going to do.

That’ll open Nethogs and start monitoring your network usage on a per-application basis. It looks something like this:

Nethogs running in the terminal.
As you can see, bandwidth monitoring on a per-application basis. Tada!

Now, if you’re going to leave it open, you can change the refresh rate. That’s done with the -d <seconds> flag. If you want it to refresh every 15 seconds, your command would look like this:

By the way, if you want to exit Nethogs, you just press Q and it closes – like top and htop do.

If you want, you can specify the network interface you want to use. It doesn’t require any flags, just the network interface name. (Read Also: how to change your network interface name.) An example of that command would be:

While the application is running, you can do some sorting/display changes with the M, R, and S keys. But it’s usually not all that complicated and sorting isn’t needed. If you’re dealing with hundreds of collections, then you may want to start sorting. Really, that’s about all you’ll ever need.

Closure:

And there you have it! You have another article to read. This one is about monitoring your network usage on a per-application basis, a pretty handy skill/tool to have. It’s pretty easy and the output is clear enough for all but the newest Linux users. If you find the tool useful, or already use the tool, please feel free to comment.

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.

Upgrade Ubuntu From The Terminal

Today’s article will show how to update and upgrade Ubuntu from the terminal. Of course, this will work on any system that uses apt, including Debian, Lubuntu, Linux Mint, etc… You can always upgrade when the GUI tells you to, but you can do it manually on your own time.

Once in a while, I come across someone who refuses to upgrade. This is a bad idea. Upgrades include things like security upgrades and they’re pretty much mandatory. It’s Linux, so you don’t “have to”, but it makes you a bad netizen because those security upgrades may very well mean your computer is being used as a spam relay or, worse, a part of a botnet.

So, please, upgrade your Ubuntu systems – and, really, all Linux boxes should get regular upgrades. I can’t emphasize this enough! Upgrade your system – if not for you then for the rest of us who have to deal with enough internet hostility. Malware exists for Linux, as does exploits for Linux and the software you have installed. Even if you don’t care about your own experiences, care about the rest of the people on the ‘net. Thanks!

For this article, we’ll be using apt. Apt is apt-get in disguise, but not quite the same. If you’re scripting you use apt-get, because it’s more stable. When you’re running commands yourself, use apt because it’s faster/easier. 

This article should be pretty quick and easy.

Upgrade Ubuntu From The Terminal:

Obviously, this article requires an open terminal. You can open one with your keyboard – just press CTRL + ALT + T and your default terminal should open.

Once you have your terminal open, we’ll go ahead and update the database (the cache) to see if any upgrades are available. To do that, you run:

It’ll tell you if upgrades are available and give you some more information – such as telling you how to see which application upgrades are available. In this case, we’re just going to upgrade everything. Like so:

That is sometimes interactive. It will want you to agree manually to the upgrades. You can just skip all that by adding a -y flag. Even better, you can now string both commands together and save some time monitoring the terminal. That command, and I use this pretty much exclusively by way of alias, is:

The && means that the next command will only run if the first has been completed successfully. You can even add autoremove to this string of commands and keep things a little cleaner automatically.

The autoremove will “remove packages that were automatically
installed to satisfy dependencies for other packages and are now no
longer needed as dependencies changed or the package(s) needing
them were removed in the meantime.” You might as well include it, as it’s pretty harmless and will save you some disk space.

Finally, there’s full-upgrade which is quite similar to the old apt-get dist-upgrade, in that it will upgrade you to a new release if both a new release is available and your settings are to upgrade to new releases (instead of staying on a LTS branch, for example). You’ll find that full-upgrade is also capable of deleting unneeded files all on its own.

To use full-upgrade, you’d still run the update first and then run the command. You can also pack them together, like so:

And there you have it. That’s about all you really need to know about upgrading Ubuntu from the terminal. It’s not hard, so just do it. Yeah, once in a blue moon it breaks something. That’s usually easily fixed and the risk is worth the benefits – to you and the rest of the internet.

Closure:

I can’t emphasize it enough – do your upgrades regularly. Now you know how to upgrade Ubuntu from the terminal, which is something I naturally do out of habit. I actually have it aliased to the ‘update’ command and it takes care of all that for me. I can’t remember the last time it broke anything – but it has to have been multiple years ago. Breakage isn’t a real risk, as things are usually heavily tested.

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: Shutdown Linux From The Terminal

Today’s article is going to tell you how to shutdown from the terminal. I’ve previously explained how to reboot a ‘frozen’ Linux system using the Magic SysReq keys. Today, we’ll shutdown from the terminal. It’s a quick and easy article – as the holidays are eating a bit of my “free” time.

Why would you want to do this? Well, if your Linux system isn’t quite frozen or your desktop GUI isn’t something you can reach, then you may want to press something like CTRL + ALT + F3. That should crack open a TTY where you can login and issue commands to your system. Maybe you’re working on a server and need to shut it down? Who knows, but the command is there and it’s a useful command to keep in mind.

For this article, we’ll mostly be using the shutdown command, and the man page defines it as:

shutdown – Halt, power-off or reboot the machine

And it does pretty much what you’d expect from such a command. However, it’s not just a basic command, there are flags and some options that go along with it. So, we might as well take the time to learn about it. After all, you never know when you want to shutdown Linux from the terminal.

Shutdown Linux From The Terminal:

Like oh so many articles, this one will require an open terminal. If you’re connected to a remote server via SSH, you already have a terminal to work with. If not, just press CTRL + ALT + T and your default terminal should open.

Once you’re ready to shutdown your Linux system, you can enter the following to shutdown immediately:

Obviously, that command will shutdown the system immediately, so don’t practice it unless you plan on shutting down – ’cause you will. You can even shutdown at a specific time by using this format (and 24h time):

You can also use the +MM function. To shutdown in 10 minutes, you’d use a command like this:

If you change that +10 to +0, it will also shutdown immediately. If you have users of the system who should be notified of an impending shutdown, then you can actually send them a message. That would look like:

So, what happens if you schedule a shutdown and need to stop it for some reason? Fortunately, the shutdown command will let you cancel an impending shutdown – so long as you get there in time. That’s done with the -c flag, of course.

If your cancellation will impact the users, you can even include a message in that. It’s done like this:

And that’s about it, really. There’s a bit more to the shutdown command, but it’s mostly going to be used in one of the ways mentioned in this article. If you want more information about the shutdown command, simply run man shutdown and read the help file.

Closure:

And there’s another article. This one will tell you how to shutdown Linux from the terminal, a handy skill to have as a user or as an admin. It may seem like a pretty basic command, but that doesn’t mean it can’t be included on the site. 

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.