{"id":6669,"date":"2018-09-10T17:14:47","date_gmt":"2018-09-10T13:14:47","guid":{"rendered":"https:\/\/www.howtoforge.com\/linux-namei-command\/"},"modified":"2018-09-10T17:14:47","modified_gmt":"2018-09-10T13:14:47","slug":"linux-namei-command-tutorial-for-beginners-5-examples","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/linux-namei-command-tutorial-for-beginners-5-examples\/","title":{"rendered":"Linux namei Command Tutorial for Beginners (5 Examples)"},"content":{"rendered":"<p>On the Linux command line, you work with several types of files, for example, directories, symbolic links, and stuff like that. Sometimes, the requirement is to know more about individual elements in a path &#8211; what type of file it is, who is its owner, and more. Thankfully, there&#8217;s an inbuilt Linux command line utility &#8211; dubbed <strong>namei<\/strong> &#8211; that lets you fetch this information.<\/p>\n<p>In this tutorial, we will discuss the basics of namei using some easy to understand examples. But before we start with that, it&#8217;s worth mentioning that all examples here have been tested on an Ubuntu 18.04 LTS machine.<\/p>\n<h2 id=\"linux-namei-command\">Linux namei command<\/h2>\n<p>The namei command in Linux follows a pathname until a terminal point is found. Following is its syntax:<\/p>\n<p class=\"command\">namei [options] pathname&#8230;<\/p>\n<p>And here&#8217;s what the man page says about this tool:<\/p>\n<pre readability=\"6\">namei\u00a0 interprets\u00a0 its\u00a0 arguments as pathnames to any type of Unix file<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (symlinks, files, directories, and so forth).\u00a0 namei then follows\u00a0 each<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 pathname\u00a0 until\u00a0 an\u00a0 endpoint\u00a0 is\u00a0 found (a file, a directory, a device<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 node, etc).\u00a0 If it finds a symbolic link, it shows the link, and starts<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 following it, indenting the output to show the context.<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 This\u00a0 program is useful for finding \"too many levels of symbolic links\"<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 problems.<\/p><\/pre>\n<p>Following are some Q&amp;A-styled examples that should give you a good idea on how the namei command works.<\/p>\n<h2 id=\"q-how-to-use-namei\">Q1. How to use namei?<\/h2>\n<p>Basic usage is fairly simple, all you have to do is to execute &#8216;namei&#8217; followed by a command line path.<\/p>\n<p>For example:<\/p>\n<p class=\"command\">namei -v \/home\/himanshu\/Downloads\/HTF-review\/Nodejs-Docker\/1.png<\/p>\n<p>And here&#8217;s the output this command produced:<\/p>\n<p class=\"command\">f: \/home\/himanshu\/Downloads\/HTF-review\/Nodejs-Docker\/1.png<br \/>\u00a0d \/<br \/>\u00a0d home<br \/>\u00a0d himanshu<br \/>\u00a0d Downloads<br \/>\u00a0d HTF-review<br \/>\u00a0d Nodejs-Docker<br \/>\u00a0&#8211; 1.png<\/p>\n<p>The tool&#8217;s man page describes in detail how to interpret the output.<\/p>\n<pre readability=\"8\">For each line of output, namei uses the following characters to identify the file type found:<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 f: = the pathname currently being resolved<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 d = directory<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 l = symbolic link (both the link and its contents are output)<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 s = socket<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 b = block device<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 c = character device<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 p = FIFO (named pipe)<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 - = regular file<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ? = an error of some kind<\/p><\/pre>\n<p>So you can see the namei command broke down all the elements in the path we supplied to it, informing us about their type.<\/p>\n<h2 id=\"q-how-to-vertically-align-namei-output\">Q2. How to vertically align namei output?<\/h2>\n<p>This you can do by using the -v command line option. For example:<\/p>\n<p class=\"command\">namei -v \/home\/himanshu\/Downloads\/HTF-review\/Nodejs-Docker\/1.png<\/p>\n<p>And here&#8217;s the output:<\/p>\n<pre>f: \/home\/himanshu\/Downloads\/HTF-review\/Nodejs-Docker\/1.png<br\/>d \/<br\/>d home<br\/>d himanshu<br\/>d Downloads<br\/>d HTF-review<br\/>d Nodejs-Docker<br\/>- 1.png<\/pre>\n<p>If you compare this with the output shown in the previous section, you&#8217;ll see there&#8217;s a vertical alignment this time around.<\/p>\n<h2 id=\"q-how-to-make-namei-show-owner-and-group-information\">Q3. How to make namei show owner and group information?<\/h2>\n<p>This can be done using the -o command line option. For example:<\/p>\n<p class=\"command\">namei -o \/home\/himanshu\/Downloads\/HTF-review\/Nodejs-Docker\/1.png<\/p>\n<p>Here&#8217;s the output:<\/p>\n<pre>f: \/home\/himanshu\/Downloads\/HTF-review\/Nodejs-Docker\/1.png<br\/>\u00a0d root\u00a0\u00a0\u00a0\u00a0 root\u00a0\u00a0\u00a0\u00a0 \/<br\/>\u00a0d root\u00a0\u00a0\u00a0\u00a0 root\u00a0\u00a0\u00a0\u00a0 home<br\/>\u00a0d himanshu himanshu himanshu<br\/>\u00a0d himanshu himanshu Downloads<br\/>\u00a0d himanshu himanshu HTF-review<br\/>\u00a0d himanshu himanshu Nodejs-Docker<br\/>\u00a0- himanshu himanshu 1.png<\/pre>\n<p>So you can see that ownership information for each file\/directory is displayed in the output.<\/p>\n<h2 id=\"q-how-to-make-namei-use-long-listing-output-format\">Q4. How to make namei use long listing output format?<\/h2>\n<p>This can be done using the -l command line option.<\/p>\n<p class=\"command\">namei -l \/home\/himanshu\/Downloads\/HTF-review\/Nodejs-Docker\/1.png<\/p>\n<p>Here&#8217;s the output:<\/p>\n<pre>f: \/home\/himanshu\/Downloads\/HTF-review\/Nodejs-Docker\/1.png<br\/>drwxr-xr-x root\u00a0\u00a0\u00a0\u00a0 root\u00a0\u00a0\u00a0\u00a0 \/<br\/>drwxr-xr-x root\u00a0\u00a0\u00a0\u00a0 root\u00a0\u00a0\u00a0\u00a0 home<br\/>drwxr-xr-x himanshu himanshu himanshu<br\/>drwxr-xr-x himanshu himanshu Downloads<br\/>drwxr-xr-x himanshu himanshu HTF-review<br\/>drwxr-xr-x himanshu himanshu Nodejs-Docker<br\/>-rw-rw-r-- himanshu himanshu 1.png<\/pre>\n<p>So you can see that an\u00a0<a href=\"https:\/\/www.howtoforge.com\/linux-ls-command\/\" target=\"_blank\" rel=\"noopener noreferrer\">ls command<\/a> like output is produced by the namei command.<\/p>\n<h2 id=\"q-how-namei-works-with-symbolic-links\">Q5. How namei works with symbolic links?<\/h2>\n<p>As already explained in the beginning, the namei command follows a symbolic link by default. For example, on my system, &#8216;link1&#8217; is a symbolic link to a file &#8216;file1&#8217;, so I passed &#8216;link1&#8217; path as input to namei in the following way:<\/p>\n<p class=\"command\">namei \/home\/himanshu\/link1<\/p>\n<p>Then the following output was produced:<\/p>\n<pre>f: \/home\/himanshu\/link1<br\/>\u00a0d \/<br\/>\u00a0d home<br\/>\u00a0d himanshu<br\/>\u00a0l link1 -&gt; file1<br\/>\u00a0\u00a0 - file1<\/pre>\n<p>So you can see the namei command clearly showed the kind of file &#8216;file1&#8217; is. However, if you want, you can force the tool to not follow symbolic links, something which you can do by using the -n command line option.<\/p>\n<p class=\"command\">namei -n \/home\/himanshu\/link1<\/p>\n<p>Here&#8217;s the output in this case:<\/p>\n<pre>f: \/home\/himanshu\/link1<br\/>\u00a0d \/<br\/>\u00a0d home<br\/>\u00a0d himanshu<br\/>\u00a0l link1 -&gt; file1<\/pre>\n<p>So you can see the tool didn&#8217;t follow symbolic link in this case.<\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>The namei command is particularly useful in case of nested symbolic link elements in path. Here, in this tutorial, we have discussed majority of the command line options this tool offers. Once you&#8217;re done practicing these, head to the tool&#8217;s\u00a0<a href=\"https:\/\/linux.die.net\/man\/1\/namei\" target=\"_blank\" rel=\"noopener noreferrer\">man page<\/a> to know more about it.<\/p>\n<div class=\"authorbox\" readability=\"15\">\n<img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/09\/linux-namei-command-tutorial-for-beginners-5-examples.jpg\" alt=\"Himanshu Arora\" title=\"\"> <\/p>\n<p><strong>About Himanshu Arora<\/strong><\/p>\n<p>Himanshu Arora has been working on Linux since 2007. He carries professional experience in system level programming, networking protocols, and command line. In addition to HowtoForge, Himanshu&#8217;s work has also been featured in some of world&#8217;s other leading publications including Computerworld, IBM DeveloperWorks, and Linux Journal.<\/p>\n<\/div>\n<div>\n<p><b>Share this page:<\/b><\/p>\n<p>\n<a href=\"https:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Fwww.howtoforge.com%2Flinux-namei-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/09\/linux-namei-command-tutorial-for-beginners-5-examples.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-namei-command%2F&amp;text=Linux+namei+Command+Tutorial+for+Beginners+%285+Examples%29&amp;via=howtoforgecom&amp;related=howtoforgecom\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/09\/linux-namei-command-tutorial-for-beginners-5-examples-1.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/howtoforgecom\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/09\/linux-namei-command-tutorial-for-beginners-5-examples-2.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/plus.google.com\/share?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-namei-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/09\/linux-namei-command-tutorial-for-beginners-5-examples-3.png\" height=\"20\" alt=\"\" title=\"\"><\/a>\n<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>On the Linux command line, you work with several types of files, for example, directories, symbolic links, and stuff like that. Sometimes, the requirement is to know more about individual elements in a path &#8211; what type of file it is, who is its owner, and more. Thankfully, there&#8217;s an inbuilt Linux command line utility [&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-6669","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/6669","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=6669"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/6669\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=6669"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=6669"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=6669"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}