Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want to make a file or folder undeletable, even the superuser can't be able to delete that file.Chattr command makes a file undeletable only if the files were in Linux filesystems (ext2,ext4). But I want to make a file undeletable which was present in ntfs filesystem.

share|improve this question

marked as duplicate by Rinzwind, Takkat, Avinash Raj, Mateo_, Nathan Osman Nov 16 '13 at 20:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
Avinash - remember - this is a Q&A site. The way we respond is by editing your question to provide further detail. Try not to respond via comments. Thanks. –  fossfreedom Nov 16 '13 at 21:32

1 Answer 1

There is not such thing that "root" can't delete. Is like telling God that he cannot do or undo something. root can put your machine topsidedown and make 1+1=3 if it likes and you can't do anything to prevent it. So, you can't prevent root from deleting whatever file he likes, just can't. Nor NTFS, nor ext2/3/4, nor HSF+, nor FAT16/32/64 not any other filesystem ruled by the OS.

The long and boring answer

Unless nobody else has root access to your system, this is impossible. But then there are ways that make users going a step beyond to delete the file, one of these is chattr:

chattr changes the file attributes on a Linux file system.

[...]

A file with the i attribute cannot be modified: it cannot be deleted or renamed, no link can be created to this file and no data can be written to the file. Only the superuser or a process possessing the CAP_LINUX_IMMUTABLE capability can set or clear this attribute.

So, if nobody has root access or capacity to boot using another operative system then the file is undeletable, otherwise any user can (and will) delete your file. The same if the filesystem is formatted and/or firmware techniques to remove data of the disks.

How to do it?

Create the file:

$ touch deletemeifyoucan:D

Protect it:

$ sudo chattr +i deletemeifyoucan\:D 
[sudo] password for braiam: 

Try to remove it

$ rm deletemeifyoucan\:D 
rm: remove write-protected regular empty file ‘deletemeifyoucan:D’? y
rm: cannot remove ‘deletemeifyoucan:D’: Operation not permitted

Now try with root:

$ sudo rm deletemeifyoucan\:D 
rm: cannot remove ‘deletemeifyoucan:D’: Operation not permitted

Unprotect it:

$ sudo chattr -i deletemeifyoucan\:D 

Is gone:

$ rm deletemeifyoucan\:D 
$ #POOF!
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.