Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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:

 $ SET FILE/ERASE_ON_DELETE SAMPLE.TXT

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:

$ DELETE SAMPLE.TXT.*

What is Linux for this?

share|improve this question
add comment

migrated from stackoverflow.com Feb 12 '11 at 20:22

This question came from our site for professional and enthusiast programmers.

4 Answers

This is supported only by some Linux filesystems:

chattr +s sample.txt

may (or may not) do what you want.

From man chattr:

NAME
       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.
...
BUGS AND LIMITATIONS
       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.

share|improve this answer
2  
Wow, you learn something new every day. Does xfs or zfs implement this flag? –  Paul Tomblin Jun 14 '09 at 16:15
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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

dd if=/dev/urandom of=FILE

It writes random bytes to FILE.

share|improve this answer
    
Not quite the same thing, but it's probably as close as you're going to get in standard Linux. –  Paul Tomblin Jun 14 '09 at 15:57
    
Oh I see. Thanks for letting me know, Paul. –  Alan Haggai Alavi Jun 14 '09 at 15:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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