linux文件加锁i属性,Linux文件的特殊属性

对于一些特殊的文件,为防止用户误操作,可以加特殊属性,示例如下:

+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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值