lsattr【コマンド】
コマンドだよ
UNIX系で使えるよ
ファイルの属性情報を表示するよ
スポンサーリンク
簡単に書くよ
lsattr【コマンド】とは
コンピュータさんに対する命令文(コマンド)のひとつ
であり
ファイルの属性情報を表示するときに使うコマンド
です。
詳しく書くよ
「lsattr」コマンドは
ファイルの属性情報を表示するときに使うコマンド
です。
UNIX系(LinuxとかMacとか)で使えます。
書き方は
lsattr [オプション] [対象のファイルやディレクトリ]
です。
オプションは、ちらほらとあります。
| オプション | 説明 |
|---|---|
| -a | ファイル名の先頭に「.(ドット)」が付くものも含め、すべてのファイルを表示する |
| -d | ディレクトリのファイル属性を表示する。このオプションを指定しないと、ディレクトリの中にあるファイルの属性を表示してしまう |
| -v | ファイルの世代情報を表示する。ファイルの中身が更新されると数字が変わるよ |
| -R | 一覧内にディレクトリがある場合はその中身も再帰的に表示する |
| -V | バージョン情報を表示する |
などです。
オプションは複数組み合わせて指定できます。
また、表示される属性は
suS-iadAcj--- ./test.txt
のように、対応するアルファベットで表現されます。
属性と対応するアルファベットの関係は以下の通りです。
| アルファベット | 属性の内容 |
|---|---|
| a | 追加モードでしかファイルを開けないよ A file with the ‘a’ attribute set can only be open in append mode for writing. Only the superuser or a process possessing the CAP_LINUX_IMMUTABLE capability can set or clear this attribute. |
| c | 圧縮されるよ A file with the ‘c’ attribute set is automatically compressed on the disk by the kernel. A read from this file returns uncompressed data. A write to this file compresses data before storing them on the disk. Note:please make sure to read the bugs and limitations section at the end of this document. |
| d | dumpプログラムが動いたときにバックアップされないよ A file with the ‘d’ attribute set is not candidate for backup when the dump(8) program is run. |
| i | 変更できないよ A file with the ‘i’ attribute cannot be modified: it cannot be deleted or renamed, no link can be created to this file and no data can be written to the file. Only the superuser or a process possessing the CAP_LINUX_IMMUTABLE capability can set or clear this attribute. |
| j | うんちゃらかんちゃら。 A file with the ‘j’ attribute has all of its data written to the ext3 journal before being written to the file itself, if the filesystem is mounted with the "data=ordered" or "data=writeback" options. When the filesystem is mounted with the "data=journal" option all file data is already journalled and this attribute has no effect. Only the superuser or a process possessing the CAP_SYS_RESOURCE capability can set or clear this attribute. |
| s | ファイルが削除されると、割り当てられていたブロックの中身が0になって、ディスクに書き戻されるよ。ごめんなさい。よく分からないです。 When a file with the ‘s’ attribute set is deleted, its blocks are zeroed and written back to the disk. Note: please make sure to read the bugs and limitations section at the end of this document. |
| t | うんちゃらかんちゃら。 A file with the ’t’ attribute will not have a partial block fragment at the end of the file merged with other files (for those filesystems which support tail-merging). This is necessary for applications such as LILO which read the filesystem directly, and which don’t understand tail-merged files. Note: As of this writing, the ext2 or ext3 filesystems do not (yet, except in very experimental patches) support tail-merging. |
| u | 削除できなくするよ When a file with the ‘u’ attribute set is deleted, its contents are saved. This allows the user to ask for its undeletion. Note: please make sure to read the bugs and limitations section at the end of this document. |
| A | アクセス時刻を更新しないよ When a file with the ’A’ attribute set is accessed, its atime record is not modified. This avoids a certain amount of disk I/O for laptop systems. |
| D | そのディレクトリが変更されたときに同期を取るよ When a directory with the ‘D’ attribute set is modified, the changes are written synchronously on the disk; this is equivalent to the ‘dirsync’mount option applied to a subset of the files. |
| E | 圧縮エラーがあるよ The ’E’ attribute is used by the experimental compression patches to indicate that a compressed file has a compression error. It may not be set or reset using chattr(1), although it can be displayed by lsattr(1). |
| I | うんちゃらかんちゃら。 The ’I’ attribute is used by the htree code to indicate that a directory is behind indexed using hashed trees. It may not be set or reset using chattr(1), although it can be displayed by lsattr(1). |
| S | そのファイルが変更されたときに同期を取るよ When a file with the ‘S’ attribute set is modified, the changes are written synchronously on the disk; this is equivalent to the ‘sync’ mount option applied to a subset of the files. |
| T | うんちゃらかんちゃら。 A directory with the ’T’ attribute will be deemed to be the top of directory hierarchies for the purposes of the Orlov block allocator (which is used in on systems with Linux 2.5.46 or later). |
| X | うんちゃらかんちゃら。 The ’X’ attribute is used by the experimental compression patches to indicate that a raw contents of a compressed file can be accessed directly. It currently may not be set or reset using chattr(1), although it can be displayed by lsattr(1). |
| Z | うんちゃらかんちゃら。 The ’Z’ attribute is used by the experimental compression patches to indicate a compressed file is dirty. It may not be set or reset using chattr(1), although it can be displayed by lsattr(1). |
面倒くさそうなところは訳していません。
ごめんなさい。
気が向いたら、そのうち訳します。
「lsattr」コマンドの使い方は、そんなに難しくありません。
例えば
lsattr test.txt
のように対象を指定して実行すれば、以下のような形でファイル名とその属性が表示されます。
-u----------- test.txt
対象を指定しないで単に
lsattr [オプション]
と打てば、現在いるディレクトリにあるファイルやデレィクトリの属性情報が表示されます。
ディレクトリの属性を表示したい場合は「-d」オプションを付けて
lsattr -d test_dir/
のように指定します。
「-d」オプションがないと「test_dir/」の属性ではなく「test_dir/」の中にあるファイルの属性が表示されます。
「-v」オプションはファイルの世代情報?を表示するオプションです。
例えば、最初に
lsattr -v test.txt
を実行したときの結果が
3504287671 -u----------- test.txt
だったとします。
「text.txt」を編集した後で もう一度コマンドを実行すると、例えば
3504287683 -u----------- test.txt
のような結果になります。
編集前と数字が変わっていますね。
「-a」オプションは全部表示しますよオプションです。
lsattr -a
を実行すると、例えば以下のような結果が表示されます。
------------- ./.bash_profile
------------- ./.
------------- ./.bashrc
------------- ./..
------------- ./.bash_logout
------------- ./.tcshrc
------------- ./.bash_history
------------- ./.cshrc
-u----------- ./test.txt
ファイル名の先頭が「.(ドット)」で始まるファイルも表示されていますね。
「-a」オプションを付けない場合は
-u----------- ./test.txt
しか表示されません。
これが「lsattr」コマンドの使い方です。
あと余談ですが「lsattr」は「list segments attribute(リスト・セグメンツ・アトリビュート)」の略だと思います。
「ls」コマンドの「ls」が「list segments(リスト・セグメンツ)」の略らしいので、それと一緒でしょう。
一言でまとめるよ
まぁ「lsattr」ってコマンドが出てきたら「ファイルの属性情報を表示するときに使うんだな~」と お考えください。
おまけ
■訳してみるよ
「ls」は多分「list segments(リスト・セグメンツ)」の略です。
「list(リスト)」の意味は「一覧表」とか「一覧表にする」とかです。
「segments(セグメンツ)」は「segment(セグメント)」+「s」です。
「segment(セグメント)」の意味は「区切り」とか「区分」とか「断片」とかです。
「attr」は多分「attribute(アトリビュート)」の略です。
「attribute(アトリビュート)」の意味は「属性」とかです。
何となく くっつけると
属性の区切りを一覧表にする
となります。
■検索してみる?






