{"id":6558,"date":"2018-09-05T21:28:36","date_gmt":"2018-09-05T17:28:36","guid":{"rendered":"https:\/\/www.howtoforge.com\/linux-lsattr-command\/"},"modified":"2018-09-05T21:28:36","modified_gmt":"2018-09-05T17:28:36","slug":"linux-lsattr-command-tutorial-for-beginners-with-examples","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/linux-lsattr-command-tutorial-for-beginners-with-examples\/","title":{"rendered":"Linux lsattr Command Tutorial for Beginners (with Examples)"},"content":{"rendered":"<p>We recently discussed <a href=\"https:\/\/www.howtoforge.com\/linux-chattr-command\/\" target=\"_blank\" rel=\"noopener noreferrer\">chattr<\/a>, a command that you can use to change file attributes on a Linux file system. To list file attributes, there&#8217;s a separate command, dubbed <strong>lsattr<\/strong>. In this tutorial, 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 mentioned in this article have been tested on an Ubuntu 18.04 LTS machine.<\/p>\n<h2 id=\"linux-lsattr-command\">Linux lsattr command<\/h2>\n<p>As already mentioned in the introduction part above, the lsattr command in Linux lists file attributes on stdout. Following is its syntax:<\/p>\n<p class=\"command\">lsattr [ -RVadlpv ] [ files&#8230;\u00a0 ]<\/p>\n<p>Here&#8217;s how the tool&#8217;s man page defines it:<\/p>\n<pre> lsattr lists the file attributes on a second extended file system.<\/pre>\n<p>Following are some Q&amp;A-styled examples that should give you a good idea on how the command works.<\/p>\n<h2 id=\"q-how-to-use-lsattr-command\">Q1. How to use lsattr command?<\/h2>\n<p>Basic usage is quite simple. Just execute &#8216;lsattr&#8217; without any command line options. Of course, you need to provide a file name as input.<\/p>\n<p>Here&#8217;s an example:<\/p>\n<p class=\"command\">lsattr file1.txt<\/p>\n<p>And here&#8217;s the output:<\/p>\n<pre>--------------e--- file1.txt<\/pre>\n<p>In addition to &#8216;e&#8217; (in the output above), there can be several other letters in the output. Following excerpt (taken from chattr man page) should give you a better idea:<\/p>\n<pre readability=\"10\"> The\u00a0 letters 'aAcCdDeijPsStTu' select the new attributes for the files:<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 append only (a), no atime updates (A), compressed (c), no copy on write<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (C), no dump (d), synchronous directory updates (D), extent format (e),<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 immutable (i), data journalling\u00a0 (j),\u00a0 project\u00a0 hierarchy\u00a0 (P),\u00a0 secure<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 deletion\u00a0 (s),\u00a0 synchronous\u00a0 updates\u00a0 (S),\u00a0 no tail-merging (t), top of<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 directory hierarchy (T), and undeletable (u).<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 The following attributes are read-only, and may be listed by\u00a0 lsattr(1)<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 but\u00a0 not\u00a0 modified by chattr: encrypted (E), indexed directory (I), and<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 inline data (N).<\/p><\/pre>\n<h2 id=\"q-how-to-make-lsattr-recursively-work-on-directories\">Q2. How to make lsattr recursively work on directories?<\/h2>\n<p>This can be done using the -R command line option.<\/p>\n<p>For example:<\/p>\n<p class=\"command\">lsattr -R Downloads\/HTF-review\/<\/p>\n<p>Here&#8217;s the output the above command produced on my system:<\/p>\n<p><a class=\"fancybox\" id=\"img-2018-08-17-155356_1366x768_scrot\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/2018-08-17-155356_1366x768_scrot.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/09\/linux-lsattr-command-tutorial-for-beginners-with-examples.png\" alt=\"How to make lsattr recursively work on directories\" width=\"500\" height=\"239\" title=\"\"><\/a><\/p>\n<p>Note that if you want to display all files in directories (including .) use the -a command line option.<\/p>\n<h2 id=\"q-how-to-make-lsattr-treat-directories-as-normal-files\">Q3. How to make lsattr treat directories as normal files?<\/h2>\n<p>By default, if you provide a directory name\/path as input to lsattr, it produces information related to files contained in that directory.<\/p>\n<p><a class=\"fancybox\" id=\"img-lsattr-1\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/lsattr-1.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/09\/linux-lsattr-command-tutorial-for-beginners-with-examples-1.png\" alt=\"How to make lsattr treat directories as normal files\" width=\"500\" height=\"49\" title=\"\"><\/a><\/p>\n<p>However, if you want, you can force lsattr to treat directory as a file, and produce file attribute information for it. This you can do using the -d command line option.<\/p>\n<p><a class=\"fancybox\" id=\"img-lsattr-2\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/lsattr-2.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/09\/linux-lsattr-command-tutorial-for-beginners-with-examples-2.png\" alt=\"lsattr -d option\" width=\"474\" height=\"35\" title=\"\"><\/a><\/p>\n<h2 id=\"q-how-to-make-lsattr-list-files-project-and-version-number\">Q4. How to make lsattr list file&#8217;s project and version number?<\/h2>\n<p>This can be done using the -p and -v command line options. Following screenshot shows both these options in action:<\/p>\n<p><a class=\"fancybox\" id=\"img-lsattr-p-v\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/lsattr-p-v.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/09\/linux-lsattr-command-tutorial-for-beginners-with-examples-3.png\" alt=\"How to make lsattr list file&#039;s project and version number\" width=\"366\" height=\"73\" title=\"\"><\/a><\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>Agreed, lsattr might not fall into the category of most used commands, but if you use chattr, then it&#8217;s a must-know command. Here, in this tutorial, we have discussed the majority of the command line options it offers. To learn more about the lsattr command, head to its <a href=\"https:\/\/linux.die.net\/man\/1\/lsattr\" target=\"_blank\" rel=\"noopener noreferrer\">man page<\/a>.<\/p>\n<div class=\"authorbox\" readability=\"15\">\n<img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/09\/linux-lsattr-command-tutorial-for-beginners-with-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-lsattr-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/09\/linux-lsattr-command-tutorial-for-beginners-with-examples-4.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-lsattr-command%2F&amp;text=Linux+lsattr+Command+Tutorial+for+Beginners+%28with+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-lsattr-command-tutorial-for-beginners-with-examples-5.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-lsattr-command-tutorial-for-beginners-with-examples-6.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/plus.google.com\/share?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-lsattr-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/09\/linux-lsattr-command-tutorial-for-beginners-with-examples-7.png\" height=\"20\" alt=\"\" title=\"\"><\/a>\n<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>We recently discussed chattr, a command that you can use to change file attributes on a Linux file system. To list file attributes, there&#8217;s a separate command, dubbed lsattr. In this tutorial, we will discuss this tool using some easy to understand examples. But before we do that, it&#8217;s worth mentioning that all examples mentioned &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-6558","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/6558","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=6558"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/6558\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=6558"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=6558"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=6558"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}