Protect your Linux files by an accidental deletion

By | November 7, 2008

You can protect your most important files from accidental deletion by giving them a “sticky bit” attribute: chmod +t filename

4 thoughts on “Protect your Linux files by an accidental deletion

  1. syphus

    That will protect files not owned by you (only from being renamed or deleted), another way to do it that would protect any file (from rename / delete / modification) is:

    chattr +i

    I think this is specific to ext2/3/4

    Reply
  2. syphus

    Actually, sticky bit only works like that on directories, from the man-page:

    RESTRICTED DELETION FLAG OR STICKY BIT
    The restricted deletion flag or sticky bit is a single bit, whose interpretation depends on the file type. For directories, it prevents unprivileged users from
    removing or renaming a file in the directory unless they own the file or the directory; this is called the restricted deletion flag for the directory, and is com?
    monly found on world-writable directories like /tmp. For regular files on some older systems, the bit saves the program’s text image on the swap device so it will
    load more quickly when run; this is called the sticky bit.

    Reply
  3. Live

    Or you can do this:

    sudo chmod 1755 file_or_folder_name, normally we just type:

    sudo chmod 755 file_or_folder_name, but the presence of 1 makes it the same as chmod +t filename as stated above.

    Then apply it recursively to the contents of a folder, so finally

    sudo chmod -R 1755 file_or_folder_name

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *