{"id":2950,"date":"2018-03-01T13:04:36","date_gmt":"2018-03-01T10:04:36","guid":{"rendered":"https:\/\/www.howtoforge.com\/linux-lscpu-command\/"},"modified":"2018-03-01T13:04:36","modified_gmt":"2018-03-01T10:04:36","slug":"linux-lscpu-command-tutorial-for-beginners-5-examples","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/linux-lscpu-command-tutorial-for-beginners-5-examples\/","title":{"rendered":"Linux lscpu Command Tutorial for Beginners (5 Examples)"},"content":{"rendered":"<p>We&#8217;ve already discussed the lshw command, which fetches data related to your system&#8217;s hardware. However, if you are only interested in CPU-related information, there&#8217;s a dedicated command line utility for that was well: <strong>lscpu<\/strong>. In this article, we will discuss this tool using some easy to understand examples.<\/p>\n<p>But before we do that, it&#8217;s worth mentioning that all examples in this tutorial have been tested on Ubuntu 16.04 LTS.<\/p>\n<h2 id=\"linux-lscpu-command\">Linux lscpu command<\/h2>\n<p>The lscpu command in Linux displays information about the CPU architecture.\u00a0 Here&#8217;s the syntax of the tool:<\/p>\n<p class=\"command\">lscpu [-a|-b|-c] [-x] [-s directory] [-e[=list]|-p[=list]]lscpu -h|-V<\/p>\n<p>And here&#8217;s what the man page says about it:<\/p>\n<pre readability=\"13\"> lscpu\u00a0 gathers\u00a0 CPU\u00a0 architecture\u00a0 information from sysfs and \/proc\/cpuinfo.\u00a0 The command <br\/>output can be optimized for parsing or for easy readability by humans.\u00a0 The information <br\/>includes, for example, the number of CPUs, threads,\u00a0 cores,\u00a0 sockets,\u00a0 and\u00a0 Non-Uniform<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Memory\u00a0 Access (NUMA) nodes. There is also information about the CPU caches and cache <br\/>sharing, family, model, bogoMIPS, byte order, and stepping.<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Options that result in an output table have a list argument. Use this argument to customize <br\/>the command output. Specify a comma separated list of column labels to limit the output <br\/>table to only the specified columns, arranged in the specified order. See COLUMNS for a <br\/>list of valid column labels. The column labels are not case sensitive.<\/p><p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Not all columns are supported on all architectures. If an unsupported column is specified, <br\/>lscpu prints the column but does not provide any data for it.<\/p><\/pre>\n<p>The following Q&amp;A-styled examples should give you a better idea on how this tool works.<\/p>\n<h2 id=\"q-how-to-use-lscpu-command\">Q1. How to use lscpu command?<\/h2>\n<p>Basic usage is pretty straight forward &#8211; all you have to do is to run the &#8216;lscpu&#8217; command sans any options.<\/p>\n<p class=\"command\">lscpu<\/p>\n<p><a class=\"fancybox\" id=\"img-lscpu\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/lscpu.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/03\/linux-lscpu-command-tutorial-for-beginners-5-examples.png\" alt=\"How to use lscpu command\" width=\"462\" height=\"550\" title=\"\"><\/a><\/p>\n<h2 id=\"q-how-to-make-lscpu-display-information-in-human-readable-format\">Q2. How to make lscpu display information in human readable format?<\/h2>\n<p>There exists a specific command line option <strong>-e<\/strong> that lets you do this.<\/p>\n<p class=\"command\">lscpu -e<\/p>\n<p>For example, here&#8217;s what the aforementioned command produced in output:<\/p>\n<p><a class=\"fancybox\" id=\"img-lscpu-e\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/lscpu-e.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/03\/linux-lscpu-command-tutorial-for-beginners-5-examples-1.png\" alt=\"How to make lscpu display information in human readable format\" width=\"500\" height=\"97\" title=\"\"><\/a><\/p>\n<p>If you want, you can also limit the output to specific columns. For example, the following command limits the output to CPU and NODE columns.<\/p>\n<p class=\"command\">lscpu -e=cpu,node<\/p>\n<p><a class=\"fancybox\" id=\"img-lscpu-e-list\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/lscpu-e-list.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/03\/linux-lscpu-command-tutorial-for-beginners-5-examples-2.png\" alt=\"lscpu command formatted result\" width=\"310\" height=\"100\" title=\"\"><\/a><\/p>\n<h2 id=\"q-how-to-limit-the-output-to-only-online-or-offline-cpus\">Q3. How to limit the output to only online or offline CPUs?<\/h2>\n<p>The lscpu command lets you limit the output it produces to only online or offline CPUs. You can do this using the <strong>-b<\/strong> and <strong>-c<\/strong> command line options, respectively.<\/p>\n<p class=\"command\">lscpu -b<\/p>\n<p class=\"command\">lscpu -c<\/p>\n<p>Note that both these command line options may only be specified together with option <strong>-e<\/strong> or <strong>-p<\/strong>.<\/p>\n<h2 id=\"q-how-to-make-lscpu-display-output-in-parsingfriendly-format\">Q4. How to make lscpu display output in parsing-friendly format?<\/h2>\n<p>You can do this using the <strong>-p<\/strong> command line option.<\/p>\n<p class=\"command\">lscpu -p<\/p>\n<p>Following is the output this command produced in my case:<\/p>\n<p><a class=\"fancybox\" id=\"img-lscpu-p\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/lscpu-p.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/03\/linux-lscpu-command-tutorial-for-beginners-5-examples-3.png\" alt=\"How to make lscpu display output in parsing-friendly format\" width=\"500\" height=\"131\" title=\"\"><\/a><\/p>\n<p>Note that just like in the case of <strong>-e<\/strong> option, you can also limit the output in this case by passing the &#8216;list&#8217; argument.<\/p>\n<p class=\"command\">&#8211;parse[=list]\n<p>Here&#8217;s what the man page has to say about the &#8216;list&#8217; argument:<\/p>\n<pre readability=\"13\">If the list argument is omitted, the command output is compatible with earlier versions of lscpu. <br\/>In this compatible format, two commas are used to separate CPU cache columns. If no CPU caches are <br\/>identified the cache column is omitted.<p>If the list argument is used, cache columns are separated with a colon (:). When specifying the <br\/>list argument, the string of option, equal sign (=), and list must not contain any blanks or other <br\/>whitespace. Examples: '-p=cpu,node' or '--parse=cpu,node'.<\/p><\/pre>\n<h2 id=\"q-how-to-make-lscpu-use-hexadecimal-masks-for-cpu-sets\">Q5. How to make lscpu use hexadecimal masks for CPU sets?<\/h2>\n<p>By default, lscpu prints CPU sets in list format (for example 0,1). However, if you want, you can have lscpu use\u00a0hexadecimal masks for CPU sets, something which you can do using the <strong>-x<\/strong> command line option.<\/p>\n<p class=\"command\">lscpu -x<\/p>\n<p><a class=\"fancybox\" id=\"img-lscpu-x\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/lscpu-x.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/03\/linux-lscpu-command-tutorial-for-beginners-5-examples-4.png\" alt=\"How to make lscpu use hexadecimal masks for CPU sets\" width=\"352\" height=\"221\" title=\"\"><\/a><\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>Like lshw, the lscpu command is also not something that you&#8217;ll require everyday, but it may save your day when the requirement arises. Here, in this tutorial, we have discussed majority of features (command line options) it offers, so practice these, and when done, head to the tool&#8217;s\u00a0<a href=\"https:\/\/linux.die.net\/man\/1\/lscpu\" target=\"_blank\" rel=\"noopener noreferrer\">man page<\/a> to know more.<\/p>\n<div>\n<p><b>Share this page:<\/b><\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>We&#8217;ve already discussed the lshw command, which fetches data related to your system&#8217;s hardware. However, if you are only interested in CPU-related information, there&#8217;s a dedicated command line utility for that was well: lscpu. In this article, we will discuss this tool using some easy to understand examples. But before we do that, it&#8217;s worth &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-2950","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/2950","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=2950"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/2950\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=2950"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=2950"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=2950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}