In VMS one may tell the file system to write junk over the existing contents of a file when it is deleted. Here is the DCL command to identify the file for this kind of treatment:


This allows the policy to be set at one point in time then later users of the file do not have to handle that detail of security. A standard delete which takes the file name out of the directory and frees the space for another file to use will also modify the existing contents to prevent the next user from reading it. The normal delete:


What is Linux for this?

4 Answers 4


This is supported only by some Linux filesystems:

chattr +s sample.txt

may (or may not) do what you want.

From man chattr:

       chattr - change file attributes on a Linux second extended file system
       When a file with the ‘s’ attribute set is deleted, its blocks are
       zeroed and written back to the disk.  Note: please make sure to read
       the bugs and limitations section at the end of this document.
       The  ‘c’, ’s’, and ‘u’ attributes are not honored by the ext2
       and ext3 filesystems as implemented in the current mainline Linux
       kernels. These attributes may be implemented in future versions of
       the ext2 and ext3 filesystems.

I do not know which specific mainline kernel versions (if any) implement this.

  • 2
    Wow, you learn something new every day. Does xfs or zfs implement this flag?
    – Paul Tomblin
    Jun 14, 2009 at 16:15

Note that with current technology you'll sometimes have no control over that. With SSD disks each write can be in done in different location, keeping old data... and this cannot be overriden by OS, filesystem or anything in software. More on http://www.anandtech.com/printarticle.aspx?i=3531.


The closest equivalent you'll typically find on unix systems is encryption. An easy way to set up an encrypted directory on Linux (and most other unices) is Encfs. Quickstart:

mkdir .ciphertext encrypted
encfs .ciphertext encrypted
# work on encrypted/file
fusermount -u encrypted

There are several other options for filesystem encryption. See How to best encrypt and decrypt a directory via the command line or script?, Best way to do full disk encryption?, and several other threads on Super User, Server Fault and Ask Ubuntu.

I don't know what threats FILE/ERASE_ON_DELETE protects against. Note that on unix, the former contents of a rewritten or deleted file can only ever be seen by the system administrator or someone with physical access to the drive: there's no “fast file creation mode” that would populate a file with random data that just happened to be in the disk region used by the file.


I am not sure if this is what you are looking for:

dd if=/dev/urandom of=FILE

It writes random bytes to FILE.

  • Not quite the same thing, but it's probably as close as you're going to get in standard Linux.
    – Paul Tomblin
    Jun 14, 2009 at 15:57
  • Oh I see. Thanks for letting me know, Paul. Jun 14, 2009 at 15:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .