A Few Ways To Count CPU Processors Or Cores

So, in today’s article we’re going to learn a few ways to count CPU processors or cores. This is something you might already know about the system in front of you, but may want to verify with a remote system.

To the Linux system, there’s little difference between an individual processor or a core, or even a thread. Each core will appear as its own processor – and that’s exactly how it should be. Linux will treat each as its own processor and do its best to take advantage of multi-core/multi-CPU systems.

Now… Hmm… I shouldn’t need to explain this, but your computer has a processor called a CPU. It may have more than one, though that’s unlikely in a personal computer. Instead, your CPU may have multiple processors on it – each functioning more or less independently as ‘cores’. Additionally, your CPU cores may have multiple threads and each of those threads will appear as its own CPU.

That’s a very simplistic overview and I have to do things like limit how many characters are in the title of the article – and I don’t really want to try to explain everything. 

For example, you could have a 4 core CPU that’s dual threaded. 4 x 2 = 8, so your system will see 8 CPUs. There’s only one physical processor, but you’re effectively working with 8 of them. (By the way, you can *sometimes* compile software optimized by the number of cores available.)

Count CPU Processors Or Cores:

(or threads, I suppose)

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.

Now, there are so many ways that you can count the CPU processors or cores. We’re just going to cover a few of them. Feel free to leave other solutions as a comment. I’ll approve the comments as quickly as I can.

Solution #1

We just recently used the ‘cpuinfo‘ file to learn about your CPU. So, we’ll start with that one first. We’ll process it with ‘grep’ and then do some counting:

It might look something like this:

output showing there are 8 CPUs available
You’ll have to use your imagination for the rest. I’m only making one screenshot.

Now, those are individual threads that it’s counting – on the same physical CPU. But, to the system they appear to be individual CPUs. I can assure you, I do not have 8 physical CPUs in my laptop.

Solution #2:

Now, your computer does technically know if it’s a physical CPU, CPU core, or CPU core thread. It just normally doesn’t much care. If your CPU and OEM vendor did things properly, you can learn that information using ‘dmidecode‘.

They do not always implement this properly and you will sometimes find mistakes when using ‘dmidecode‘. Let’s hope for the best when we run this more convoluted command:

That one uses egrep and picks out multiple words to include. If you run that command, you should find out that your computer really can tell the difference between cores and threads – and physical CPU count (though not with this command).

Solution #3:

This final solution is nice and easy. If you’re gonna memorize one of these, this would be the one to memorize. In fact, if you’re going to need to count CPU processors or cores, you might just as well use this one. It’s easy and effective.

That one will output the total number of CPUs, cores, or threads. That’s all it will output, just a single number. That number is how many CPUs (effectively) your computer sees – and that’s it. It’s pretty much perfect.

Closure:

There you go. You have another article, this one explaining how to count CPU processors or cores (or threads, really). It’s handy information to know, though you probably already know it. Like I mentioned above, you can optimize C/C++ code to run on the specific number of cores – and there are other reasons you might want to know this. 

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.

One Way To See CPU Information

Today, we’re going to explore one way to see CPU information. On the original site, I had a couple of articles about this sort of stuff but we didn’t cover this method. It’s a short and sweet process, though I’ll show you a couple of ways to process the output.

The date that this will be published is July 4th. That’s a holiday in the United States. Not only do I live here, the vast majority of my readers live here (according to the stats I have). So, this will be a nice and easy article. For those of you who reside elsewhere, you’re welcome. You won’t have to work too hard today to understand what’s going on.

Anyhow, we’re not going to use any special tools. We’re not going to use any applications that you don’t already have installed. While we likely could, there really isn’t any need to. This being Linux, the information we’re after is already in a file. All we need to do is read that file.

So, let’s get to it…

How To See CPU Information:

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.

With your terminal now open, let’s go ahead and read the file we need if we want to see the CPU information:

That’ll output a ton of text. You can read it as it is, or you can actually get it in a more readable form using the ‘less’ command. To do that, you just change out the ‘cat’ command, like so:

Now, just use the arrows on your keyboard to scroll down (or back up) through the text. When you want to close the output and return to the terminal, just press Q and it will close.

Closure:

That’s it. That’s all there is to this article that tells you how to see CPU information. It’s not a very tough article, and it’s quick. So, I met those goals! Yay me! Enjoy your holiday, even if the holiday is just a nice quick article that doesn’t require much thinking. Me? I’ll drink some beer and char some dead animal flesh.

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 Delete An Entry In Your Bash History

In today’s article, we’re going to learn how to delete an entry in your ‘bash’ history. It’s a useful skill to have, for any number of reasons. It’s not all that difficult and this shouldn’t be a very long article. Read on, my dear readers! Even a long-term Linux user might learn something – but I make no promises!

I’ve previously covered how to remove duplicates from your bash history. It may be worth checking that article out, as most of you are going to be using bash. Sure, there are other shells, but bash is the most common on desktops and servers. So, we might as well learn with bash.

If you don’t know, bash is both a language and an application. Unless otherwise specified, you’re almost certainly using bash when you open a terminal or TTY. 

When you enter a command in the terminal or TTY, it’s saved to your bash history. In fact, it’s saved to the hidden file ~/.bash_history. If you so wanted, you could just open the .bash_history file with a text editor and remove lines as you wished. That works just fine.

However, in this article we’ll be using the ‘history’ command. It’s a handy command, useful for recalling previously entered commands and managing those stored commands. I guess this is really more an article about performing some very basic tasks with the history command. Like I said, it’s good for you to know this sort of stuff – especially as a Linux beginner.

Delete An Entry In Your Bash History:

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 right up and be ready for use!

So, with your handy-dandy freshly-cracked-open terminal, let’s just display your bash history. You’re going to do that with just the following command:

You’ll notice that every stored command from your bash history is assigned a number that’s shown on the left (or right, if you use a RTL language). Well, that’s how you delete it. You use that number in the following command:

You can use that command to delete an entry in your bash history, and you can do so as often as you’d like. While you’re there, you can also just plain clear your entire bash history with this command:

That will clear all of your bash history – more or less. Your current session may have not been written to the history at the time you issued that command. It might not be saved until you close the terminal instance. This makes it slightly more complicated to make sure the history is truly empty. However, it’s definitely close enough.

Anyhow, you might want to delete your bash history to remove commands that you’ve memorized. You might want to remove commands that didn’t work. If there are sensitive commands in your bash history, this is a way to remove them, surgically or en masse. There are all sorts of reasons why you might want to go through your bash history to delete past commands – and now you can!

Closure:

Yay! It’s another back-to-basics kind of article. In this one, we learn how to delete an entry in your bash history file. In some cases, it may be easier for you to just do so with a GUI and a GUI text editor. You don’t even need ‘sudo’ to make the changes and removing a lot of entries might be faster with a graphical application. Just remove the lines you don’t want showing up in the history any longer.

Also, I should mention somewhere that you can see the history by just pressing the up arrow, but I suspect folks will already know that. ‘Snot the best way to go about managing them, but you can see and select them, running them again as you wish.

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.

Sort Files By Size (In The Terminal)

In today’s article, we’re going to cover something nice and simple; how to sort files by size in the terminal. This is something everyone should know, because sorting files is often a prerequisite to understanding and managing said files.

Besides, not all the articles have to be something complicated. The tagline for Linux-Tips is “Getting you up to speed!” It’s supposed to be aimed squarely at new Linux users. The problem is, many of those articles are boring to write and the 2nd largest group of readers aren’t really beginners. 

So, yeah…

Today, we’ll have a nice, basic article that tells you how to sort files by size – in the terminal. In fact, some of the more regular users may not have these commands memorized. Now’s a good time to learn ’em.

We’ll be using the ‘ls’ command for this. It is said that you shouldn’t parse the output of ‘ls’ for anything important. It’s bad practice for reasons I think I’ve touched on before. However, you can safely use ‘ls’ for this process as it’s just sorting the files by size and doing so by itself.

For those that don’t know, ‘ls’ has a ton of options. It’s a tool used to show the contents of a directory. You can use man ls to get more information about the command. We’ve previously covered:

Let’s Use ‘ls’ To Sort Files By Time

Well, today we’ll use ‘ls’ to …

Sort Files By Size:

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.

You might just as well stay right there in your default location – which should be your home directory. Feel free to switch to a new directory, but you really won’t need to. It’s an easy command. 

First, we’ll show the output sorted to show the largest files first:

Of course, you can reverse that sort order and show the smallest files first. To do that, you just add -r (reverse) to your flags, like so:

That command should show you files listed with the smallest ones first and that’s really all there is to this article. Well, there’s the closure section – but nobody reads those.

Closure:

And, well, this particular closure section won’t have anything truly interesting or different in it. After all, this is just a simple article that shows you how to sort files by size. ‘Snot that much more to it. ‘Snot that much more that I can add.

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: Make ‘wget’ Ignore Certificate Errors

In today’s article, we’ll learn how to make ‘wget’ ignore certificate errors. It’s an easy thing to do and can be pretty useful if you want to download stuff from a server with a broken or missing security certificate. It’s a simple process, one which even a new Linux user can follow – but it’s not one that comes up all that often and so it’s worth including here.

I’d like to save some time and not duplicate work, so I’d appreciate it greatly if you at least read the intro section from when I wrote how to make ‘curl’ ignore certificate errors.

That’s right, I’ve already written this article – except it was for ‘curl‘ and not for ‘wget’.  Well, this article is pretty much the same thing, except we’re talking about doing it with ‘wget’. So, read the intro to the curl article and you’ll be up to speed with regards to what a certificate is, why they’re important, and why you might want to ignore certificate errors.

That’ll save some time! Those of you who do not read the ‘curl’ article are on your own. Also, many of my readers will already know about security certificates and won’t need a tutorial or refresher course. 

By the way, we use SSL here on Linux Tips. In fact, we use HSTS Preload, which means it’s hard coded in Chromium browsers (or at least Chrome) and the site will simply refuse to load without a proper certificate. So, there’s that… I take security pretty seriously, something important when you’re using WordPress.

Make ‘wget’ Ignore Certificate Errors:

This article requires ‘wget’ which 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. If ‘wget’ isn’t installed, install it. I am pretty darned confident that it’s in your default repositories.

If you don’t know, ‘wget’ is used to download stuff from servers – while  you’re using your terminal. It’s a basic concept, but the command can be pretty complicated. After all, there are some pretty complicated site structures out there, and of course your downloading needs will vary.

So, with that said, it’s really easy to do this. You’ll just use the “--no-check-certificate” flag, like so:

But wait, there’s more! You can actually make the ‘wget’ command ignore certificate errors all the time. If this is something you find yourself needing to add this to your ‘wget’ commands often, you can make it permanent. To do that, you just need to edit your ~/.wgetrc file (create it, if it doesn’t exist) with the following:

You won’t have to reload anything, that command should take effect the very next time you use the ‘wget’ command and you should now permanently be ignoring security certificate errors. 

Doing this might actually be a horrible idea. After all, you’re ignoring security warnings. That’s a bit like ignoring a ‘Bridge Closed’ sign and hoping for the best as you gun it to the tune of “Highway To The Danger Zone”. Or, it could be just fine ’cause not everything even needs a security certificate! It’s Linux. You get to decide.

Closure:

Whelp… You have a new article. In this one, I give you what could be horrible advice. You might not want to make ‘wget’ ignore certificate errors. I mean, they are security related. On the other hand, it’s likely just fine – assuming you do some basic verification. Ah well… I ain’t scared and it’s not my computer. I’ll happily teach you how to completely break your system. I ain’t scared.

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.