chattr and lsattr command Detailed

 

lsattr command

lsattr command is used to view files second extended file system attributes.

 

grammar:

lsattr (option) (parameters)

 

Options:

-E: display the current value of the device attribute, but the current value is obtained from the database in the user equipment, rather than obtained directly from the device.
-D: Displays the name of the property, if the default value of the property, description, and the user can modify the flag attribute values.
-R: recursive mode of operation;
-V: display version information instruction;
-a: lists all files in a directory, including hidden files.

  

 lsattr often use several options -D, -E, -R can not use these three options together, they are mutually exclusive, when there -l, -H, use the lsattr frequently used, it must be noted specific device name to be displayed with the -l option indicates that the logical name of the device, otherwise use the -c, -s, -t other options only determine whether a device that already exists.

 

 

chattr command

chattr command to change file attributes. The instructions may change stored on the ext2 file system file or directory attributes that total the following 8 modes:

a: Let the file or directory is for additional uses;
b: do not update the last access time of the file or directory;
c: After the file or directory compression storage;
d: the file or directory exclude tilting operation;
i: not any change on the file or directory;
s: Confidentiality delete files or directories;
S: Instant update the file or directory;
u: prevent accidental erasure.

  

grammar:

chattr (option)

 

Options:

-R: recursive processing, all files and subdirectories under the directory together with the processing instructions;
-v <version number>: set the file or directory versions;
-V: display process execution instruction;
+ <Property>: open the properties file or directory;
- <property>: close the file or directory that property;
= <Attribute>: This attribute specifies the file or directory.

  

 

1, with the chattr command to prevent a critical system files are modified:

# chattr +i /etc/resolv.conf

Then mv /etc/resolv.conf to the file operation command and the like, are the results obtained in Operation not permitted.

vim can edit the file when prompted W10: Warning: Changing a readonly file error. To modify this file should i just get rid of property:

chattr -i /etc/resolv.conf

  

Use the lsattr command to display file attributes:  

# lsattr /etc/resolv.conf

## output:
----i-------- /etc/resolv.conf

  

2, so that a file can only be entered, and additional data, but can not be deleted for a variety of log files:

# chattr +a /var/log/messages

  

Detailed:

 

-e 的解释是`The e attribute indicates that the file is using extents for mapping the blocks on disk.`

   : E attribute indicates that the file is used to map extents blocks on the disk

-I 的解释是`The I attribute is used by the htree program code to indicate that a directory is being indexed using hashed trees.`

: I htree code uses I attribute to indicate a hash index directory tree

The 'e' indicates property, the extents in the file using the block map on disk. extents here we can be understood as a continuous range. This property is not removed by chattr.

 

 

 

Explanation chattr and lsattr description

lsattr: View special privileges
chattr: to change the attributes of files on EXT2 file system

usage

chattr [+ - =] [ASacdistu] [file or directory name]

  

chattr change a file on the file system attributes EXT2
Parameter Symbol format is  +-=[acdeijstuADST]
operator   '+'  indicates on the selected attributes added to the specified file; ' -' indicates delete the attribute; '=' represents a file provided only specified properties

Parameter Description:

+ - =: are "+" (increase), "-" (reduced), "=" (setting) properties

 

  • A: When the attribute is set A, the file (or directory) access time atime (access) would not be modified, such as a laptop computer can be avoided easily with disk I / * O error occurs;

  • S: This feature is somewhat similar to sync, data synchronization is written to disk, it can effectively prevent data loss;

  • a: After setting a, this file will only increase the data can not be deleted, only root can set this property;

  • c: After setting this property, this file is automatically compressed and decompressed when read automatically. But when it was stored, it will now be compressed in memory (useful for large files *);

  • d: when the dump (backup) program execution, the attribute is set to allow the document d (or directory) has a dump efficacy; + d can skip the backup file

  • i: This parameter allows a file "can not be deleted, renamed, set links, can not write data to system security are very helpful

  • j: When using ext3 file system format will set the attribute file when j is written first in the log, but when the parameter is set to filesystem data = jour * when nalled, since the log has already been set, so the property is invalid

  • s: s is set when the file parameters, it will be completely moved out of the hard disk space

  • u: contrary to s, u when using configuration files, data content can actually exist on disk, can be used to undelete

  • Large files (h),

  • Compression error (E),

  • Index catalog (I),

  • Compression of the original access? (X),

  • Compressed and fragmented files (Z).

 

 

Introduction

    In addition to ext2 among other common file systems such as ext3 ext4 NTFS, etc. are journaled file system, the so-called journaling file system that is all there is behavior will be recorded on the disk, the system will reserve some space to record the behavior of the operation, when the system when abnormal shutdown and then boot, does not need to restore the full scanning system to a normal state.

    Since Linux kernel 2.6.28 officially support the new file system Ext4. Ext3 Ext4 is an improved version, modified some important data structures in Ext3, Ext2 to Ext3 not just like that, just added a log function only. Ext4 can provide better performance and reliability, as well as richer features:

 

1. compatible with Ext3.
    Perform several commands, you can migrate online from Ext3 to Ext4, without having to reformat the disk or reinstall the system. Ext3 still retain the original data structure, Ext4 act on new data, of course, the entire file system will thus gaining a greater capacity Ext4 support.

2. larger file systems and larger files.
    Ext3 than the current maximum supported file systems and 16TB maximum 2TB file, Ext4 respectively support 1EB (1,048,576TB, 1EB = 1024PB, 1PB = 1024TB) file system, as well as 16TB of files.

3. unlimited number of subdirectories.
    Ext3 currently only supports 32,000 subdirectories, and Ext4 support an unlimited number of subdirectories.

4. Extents.
    Ext3 indirect block mapping, when a large file operation, extremely inefficient. For example, a 100MB size of the file, in Ext3 25,600 to establish the data blocks (data block size for each 4KB) mapping table. Ext4 introduces the popular concept extents modern file systems, each extent is a contiguous set of data blocks, said document is represented as a "data file stored in the next data block 25,600" to improve the efficiency of many .

5. Multi-block allocation.
    When writing data to the Ext3 filesystem, Ext3 data block allocator can only allocate a block of 4KB, write a 100MB file will call 25,600 times the data block allocator, and Ext4 multi-block allocator "multiblock allocator "(mballoc) supports a plurality of data blocks allocated one call.

6. delayed allocation.
    Ext3 data block allocation policy is assigned as soon as possible, and Ext4 file Caozuojitong and other modern distribution strategy is to delay as much as possible, until it began to file written data block is allocated and written to the disk cache, so that we can optimize the entire document data block allocation, together with the first two characteristics can significantly improve performance.

7. Quick fsck.
    Previously executed fsck first step will be very slow, because it checks all of the inode, inode table for now Ext4 each group has been added to a list of unused inode in the future fsck Ext4 file system can skip them but only to check in with those of the inode.

8. verification log.
    Log is the most common part, also easily lead to disk hardware failure, and recover data from damaged log data will lead to more damage. Ext4 log check function can easily determine whether the log data corruption, and it will Ext3 two-stage mechanism combined into a log phase, increase safety and improve performance.

9. "No Log" (No Journaling) mode.
    Log there is always some overhead, Ext4 allowed to close the log, so that certain users have special needs can take to improve performance.

10. The online defragmentation.
    Although the delayed allocation, multi-block allocation and extents can effectively reduce file system fragmentation, but fragmentation inevitably occur. Ext4 supports online defragmentation, and will provide e4defrag tool to defragment individual files or entire file system.

11. inode related features.
    Ext4 support larger inode, the inode size default Ext3 than 128 bytes, Ext4 accommodated in the inode for more extended attributes (e.g., inode or version stamp nanoseconds), the default inode size is 256 bytes. Ext4 also supports extended attributes fast (fast extended attributes) and inode reserved (inodes reservation).

12. The pre-allocated persistent (Persistent preallocation).
    P2P software to download a file in order to ensure there is enough space to store, often pre-created with the same size of the downloaded file empty file, so within the next few hours or a few days out of disk space download fails. Ext4 file system level to achieve a lasting pre-allocation and provide the appropriate API (posix_fallocate libc in ()), application software more efficient than their own.

13. enabled by default barrier.
    Equipped with an internal cache on disk, in order to re-adjust the order of bulk data write operation, the write performance optimization, the file system must be written in the log data in order to write commit record after the disk, if the commit record is written earlier, but it is possible to log damage, it will affect data integrity. Ext4 enabled by default barrier, only when the data is written before the barrier entire disk to write data after the barrier. (By "mount -o barrier = 0" command to disable this feature.) .
    Options O-mount embodiment mainly describes the device or file. Common parameters are:
    Loop: used to partition a hard disk as a file system mounted on
    ro: using equipment mounted read-only
    rw: mounts the reader device using
    iocharset: access the file system specified character set

    In Microsoft Winsows the world, the hard disk can be formatted into a different format NTFS, FAT32, FATl6 and so on. Similarly, under the GNU / Linux is also available in many different file system format. Currently under GNU / Linux, there are these types of commonly used formats: Ext2 / Ext3, ReiserFS, XFS and JFS and several kinds.
 
    In addition to Ext2, several other are journaled file system. So what is journaled file system? The system is a multi-state data with some additional hard disk space record, so after unusual switch machine without re-scanning the entire hard drive to restore the system to normal state.

 

 

 

Question 1: the file is using extents ..., but why lsattr directory Why there are `-e option?

Why directory will display -e -Iissue that I think is the accuracy of the documentation problem man, we all know: Linux under everything is a file. Here is the file expressed its wish that all files are supported, but why not support linked files, here we have soft noticed that the figure is a link directory, we will look at is whether the file can be displayed properly soft

 

# lsattr /etc/system-release
lsattr: Operation not supported While reading flags on /etc/system-release

 Find soft file is not enough 

 

 

Question 2: What is extents, extended here is difficult to understand?

lsattrThe -e means extents, refers ext (2,3,4) Series file system supported Extentsproperty, often after a lot of searching to find, found that the property have a special presentation

    Ext3 file system and other indirect block mapping, mainly for large file operations, today's science and technology development and popularization of technology, capacity-scale hardware upgrade very fast, when operating large files, large data, extremely inefficient. For example, a 100MB size of the file in the file system to establish Ext 25,600 data blocks (data block size for each 4KB) mapping table.

    To solve this problem, the introduction of a popular concept Ext4 extents modern file systems, each extent is a contiguous set of data blocks, said document is represented as a "data file stored in the next data block 25,600", improve a lot of efficiency.

    It -erefers to a file system file or directory supports this feature, this feature plays a very important role in modern operating systems.

 

 

Problem 3: The I attribute is used by  the htree program code, htreewhat is?

Because man is to introduce the document is htree programe, so at first I was as it should be understood as a system command, but after verification not found a system command.

yum whatprovides htree

  

The problem here so far, I think the word is not enough as I understand this sentence, so at that time it did not put too much thought, but later found that this idea is wrong! !

Btrfs: B-tree file system

In fact, a file system, you can btrfs file system wiki, there's also introduced here here  

 

 

Question 4: indicate that a directory is being indexed using hashed trees. indexed using hashed treesIt cited?

    The initial understanding is indexed directory will be too soft -Ioption, but us verify this figure from the above execution llreturns the result of command in the second column of numbers, there are all directories are linked, but the lsattrcommand returns results but not all have the directory attribute I. Therefore, this option can only guess and verified. After a closer look chattr command to find the property It may not be set or reset using chattr(1). The concept of this option can only guess:

    系统对特有的常被引用或其它程序调用的目录添加该属性,以提升速度和提高效率。

 

Do a simple verification. The default directory is not created their own Iproperty

The default directory is not created their own Iproperty

----------I--e- /lib64
----------I--e- /etc
-------------e- /home
-------------e- /lib
----------I--e- /lib64
----------I--e- /sbin

These common lib libraries and system files are often called I attribute it will be added.

 

 

 

Give out Description:

We have such a demand: the Linux file system does not allow others to modify, delete or add only allows, we can use the chattr command.

[Test serv01 the root @] note.txt CAT # 
1. allowed late
2. allowed to leave early
3. forbidding smoking
[root @ serv01 test] # chattr + i note.txt

#root users can not edit
[root @ serv01 the Test] # vim note.txt 
[root @ serv01 the Test] # CAT note.txt
1. must not be late
2. not allowed to leave early
3. forbidding smoking

#root用户不能删除 修改
[root@serv01 test]# rm -f note.txt
rm: cannot remove `note.txt': Operation not permitted
[root@serv01 test]# echo "this is test" >> note.txt
-bash: note.txt: Permission denied

#ll view the file properties can not see, you need to use the lsattr see
[root @ serv01 the Test] # LL note.txt
-rw-r -. r-- 1 root root 45 Sep 21 17:46 note.txt
[root @ serv01 the Test] # the lsattr note.txt
---- i -------- E- note.txt

#root users can not modify is a relative concept, root user can modify the file's properties, you can modify the
[root @ serv01 the Test] # the chattr -i note.txt
[root @ serv01 the Test] # the lsattr note.txt
---- E- note.txt ---------
[@ serv01 the root Test] Vim note.txt #
[@ serv01 the root Test] note.txt CAT #
1. allowed late
2. allowed to leave early
3. forbidding smoking
4. you can not come to work

# Message Board: what he says can not remove
[root @ serv01 the Test] # vim note.txt
[root @ serv01 the Test] # CAT note.txt
1. must not be late
2. not allowed to leave early
3. allowed to smoke
4. You can not come to work
hello
[Test serv01 the root @] + # A note.txt the chattr
[@ serv01 the root Test] note.txt the lsattr #
----- ------- A note.txt E-
[@ serv01 the root Test] # Vim note.txt
[root @ serv01 the Test] # LS
note.txt note.txt note.txz ~ ~ ~ note.txy  
# delete, find no authority 
[root @ serv01 the Test] # RM -rf *
RM: `note the remove Regular File .txt 'the y-?
RM: CAN not the Remove `note.txt': Operation not permitted
[root @ serv01 the Test] # LS
note.txt the Upload
[root @ serv01 the Test] # echo" the Hello world "> note.txt 
-bash: note .txt: Operation not permitted
# Use only way to add additional content
[root @ serv01 the Test] # echo "the Hello world" >> note.txt 
[root @ serv01 the Test] # CAT note.txt 
1. must not be late
2. not allowed to leave early
3. forbidding smoking
4 You can not come to work
the Hello
the Hello world

[root@serv01 test]# chattr -a note.txt 
[root@serv01 test]# lsattr note.txt 
-------------e- note.txt

 

 

Guess you like

Origin www.cnblogs.com/morgan363/p/11735769.html