效果:只能添加,不能修改或删除:
典型应用:日志
操作:chflags uappnd命令,该命令使用文件只能添加不能更改,也不能删除
user@test:~/test % chflags uappnd 1.txt
查看
user@test:~/test % ls -lo 1.txt
-rw-r--r-- 1 test wheel uappnd 211 Oct 27 10:20 1.txt
验证1,使用重定向命令,可以添加,不可以重写:
user@test:~/test % echo "ssdddff" > 1.txt
1.txt: Operation not permitted.
user@test:~/test % echo "ssdddff" >> 1.txt
验证2,删除,会提示无权限
user@test:~/test % rm 1.txt
override rw-r--r-- test/wheel uappnd for 1.txt? y
rm: 1.txt: Operation not permitted
验证3,php的file_put_contents函数,注意第三个参数,FILE_APPEND代表添加而不是覆写,先看添加模式,最后用tail命令输出最后一行来验证:
user@test:~/test % cat tt.php
<?php
file_put_contents('1.txt',"sdkfjsldkfsldf\n",FILE_APPEND );
?>
user@test:~/test % php tt.php
user@test:~/test % tail -n 1 1.txt
sdkfjsldkfsldf
覆写模式,提示权限不足:
user@test:~/test % cat t.php
<?php
file_put_contents('1.txt',"sdkfjsldkfsldf\n" );
?>
user@test:~/test % php t.php
PHP Warning: file_put_contents(1.txt): failed to open stream: Operation not permitted in /home/test/test/t.php on line 2
验证4,php的fopen函数:
w模式,提示权限不足:
user@test:~/test % cat tf.php
<?php
$fp = fopen('1.txt',"w" );
fclose( $fp );
?>
user@test:~/test % php tf.php
PHP Warning: fopen(1.txt): failed to open stream: Operation not permitted in /home/test/test/tf.php on line 2
PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /home/test/test/tf.php on line 3
a模式:
user@test:~/test % cat ta.php
<?php
$fp = fopen('1.txt',"a" );
fwrite( $fp , "the fourth test!\n");
fclose( $fp );
?>
user@test:~/test % php ta.php
user@test:~/test % tail -n 1 1.txt
the fourth test!
c模式:
user@test:~/test % cat tc.php
<?php
$fp = fopen('1.txt',"c+" );
fwrite( $fp , "the fourth test!\n");
fclose( $fp );
?>
user@test:~/test % php tc.php
PHP Warning: fopen(1.txt): failed to open stream: Operation not permitted in /home/test/test/tc.php on line 2
PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /home/test/test/tc.php on line 3
PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /home/test/test/tc.php on line 4
系统级append Only,普通用户也会提示权限不足
user@test:~/test % chflags sappnd 2.txt
chflags: 2.txt: Operation not permitted
user@test:~/test % su
Password:
root@mm:/home/test/test # chflags sappnd 2.txt
root@mm:/home/test/test # exit
user@test:~/test % ls -lo 2.txt
-rw-r--r-- 1 test wheel sappnd 289 Oct 27 10:50 2.txt
验证:
user@test:~/test % cat t.php
<?php
file_put_contents('2.txt',"sdkfjsldkfsldf\n" );
?>
user@test:~/test % php t.php
PHP Warning: file_put_contents(2.txt): failed to open stream: Operation not permitted in /home/test/test/t.php on line 2
该贴由hui.chen转至本版2014-11-5 17:04:52