Monday, July 9, 2012

Disable append files in Linux



Appending the files sometimes may erase the existing data. For security purpose you can use noclobber command to prevent this.

[root@tester ~]# cat > testers.txt
append the data to test
[root@tester ~]# cat testers.txt
append the data to test

Set noclobber using the following syntax and you will not be able to append the file there after.

[root@tester ~]# set -o noclobber testers.txt
[root@tester ~]# cat > testers.txt
-bash: testers.txt: cannot overwrite existing file

You can remove the noclobber using the below syntax.

[root@tester ~]# set +o noclobber testers.txt
[root@tester ~]# cat >> testers.txt
test completed
[root@tester ~]# cat testers.txt
append the data to test
test completed

No comments: