对于一些特殊的文件,为防止用户误操作,可以加特殊属性,示例如下:
+i:锁定
示例文件:
[root@centos76 data]#ll test.txt
-rw-r--r--. 1 root root 48 Mar 12 19:30 test.txt
+i锁定文件
[root@centos76 data]#chattr +i test.txt
查看文件属性,发现与之前一样
[root@centos76 data]#ll test.txt
-rw-r--r--. 1 root root 48 Mar 12 19:30 test.txt
进行验证+i功能是否生效
重定向内容:
[root@centos76 data]#echo 1111 > test.txt
** -bash: test.txt: Permission denied **
查看一下:
[root@centos76 data]#cat test.txt
abcdedf
abcdedf
abcdedf
fdedcba
fdedcba
fdedcba
重命名:
[root@centos76 data]#mv test.txt haha.txt
**mv: cannot move ‘test.txt’ to ‘haha.txt’: Operation not permitted**
删除文件:
[root@centos76 data]#rm -f test.txt
**mv: cannot remove ‘test.txt’: Operation not permitted**
+a:只能追加
示例文件:仍然采用上次测试的test.txt文件
[root@centos76 data]#chattr +a test.txt
重定向内容:
[root@centos76 data]#echo 222 > test.txt
**-bash: test.txt: Operation not permitted**
重命名:
[root@centos76 data]#mv test.txt haha.txt
**mv: cannot move ‘test.txt’ to ‘haha.txt’: Operation not permitted**
删除:
[root@centos76 data]#rm -f test.txt
**mv: cannot remove ‘test.txt’: Operation not permitted**
追加内容:
[root@centos76 data]#echo 222 >> test.txt
[root@centos76 data]#cat test.txt
abcdedf
abcdedf
abcdedf
fdedcba
fdedcba
fdedcba
222
+A:锁定atime的时间,减少读文件对磁盘IO的影响,以提高性能。
[root@centos76 data]#chattr +a test.txt
第一次读取,记录atime的时间
[root@centos76 data]#cat test.txt
333
444
555
[root@centos76 data]#stat test.txt
File: ‘test.txt’
Size: 12 Blocks: 8 IO Block: 4096 regular file
Device: 803h/2051d Inode: 83 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:etc_runtime_t:s0
**Access: 2019-03-18 11:12:50.425400248 +0800**
Modify: 2019-03-18 11:03:18.770446437 +0800
Change: 2019-03-18 11:12:42.139400918 +0800
Birth: -
第二次读取,atime时间没有变化,如下:
[root@centos76 data]#cat test.txt
333
444
555
[root@centos76 data]#stat test.txt
File: ‘test.txt’
Size: 12 Blocks: 8 IO Block: 4096 regular file
Device: 803h/2051d Inode: 83 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:etc_runtime_t:s0
**Access: 2019-03-18 11:12:50.425400248 +0800**
Modify: 2019-03-18 11:03:18.770446437 +0800
Change: 2019-03-18 11:12:42.139400918 +0800