https://www.howtoforge.com/linux-lsattr-command
We recently discussed chattr, a command that you can use to change file attributes on a Linux file system. To list file attributes, there'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's worth mentioning that all examples
mentioned in this article have been tested on an Ubuntu 18.04 LTS
machine.
Here's an example:
For example:
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.
We recently discussed chattr, a command that you can use to change file attributes on a Linux file system. To list file attributes, there's a separate command, dubbed lsattr. In this tutorial, we will discuss this tool using some easy to understand examples.
Linux lsattr command
As already mentioned in the introduction part above, the lsattr command in Linux lists file attributes on stdout. Following is its syntax:
lsattr [ -RVadlpv ] [ files... ]
Here's how the tool's man page defines it:lsattr lists the file attributes on a second extended file system.Following are some Q&A-styled examples that should give you a good idea on how the command works.
Q1. How to use lsattr command?
Basic usage is quite simple. Just execute 'lsattr' without any command line options. Of course, you need to provide a file name as input.Here's an example:
lsattr file1.txt
And here's the output:--------------e--- file1.txtIn addition to 'e' (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:
The letters 'aAcCdDeijPsStTu' select the new attributes for the files: append only (a), no atime updates (A), compressed (c), no copy on write (C), no dump (d), synchronous directory updates (D), extent format (e), immutable (i), data journalling (j), project hierarchy (P), secure deletion (s), synchronous updates (S), no tail-merging (t), top of directory hierarchy (T), and undeletable (u). The following attributes are read-only, and may be listed by lsattr(1) but not modified by chattr: encrypted (E), indexed directory (I), and inline data (N).
Q2. How to make lsattr recursively work on directories?
This can be done using the -R command line option.For example:
lsattr -R Downloads/HTF-review/
Here's the output the above command produced on my system:
Note that if you want to display all files in directories (including .) use the -a command line option.
Q3. How to make lsattr treat directories as normal files?
By default, if you provide a directory name/path as input to lsattr, it produces information related to files contained in that directory.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.
No comments:
Post a Comment