Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using Ubuntu 10.04. I have a large directory with (many sub-directories) and data files I use quite often in my scripts. I would like to make sure I never accidentally remove/overwrite/change any of the files/directories in this super directory.

How can I do that?

share|improve this question
Consider using version control like git. – Sathya Sep 12 '10 at 14:59
up vote 3 down vote accepted

Mostly ordered by decreasing protection and increasing convenience:

  • Store the files on physically read-only media such as a CD-ROM.

  • Store the files on a separate filesystem that you mount read-only.

  • If you are the administrator, create another user and make these files owned that another user.

  • Use FUSE bindfs (Ubuntu package bindfs) to create a read-only view of the directory tree, and point your scripts at this read-only view:

    bindfs -p a-w /path/to/actual/tree /path/to/readonly/view
    myscript -d /path/to/readonly/view
  • Make the directory tree read-only with chmod a-w /path/to/tree.

  • Create a copy of the tree with hard linked files and point your script to the copy. Then your scripts might still modify existing files, but if they create, remove or replace files, that will only affect the copy.

    cp -al /path/to/actual/tree /path/to/readonly/view
    myscript -d /path/to/readonly/view

I recommend that you use bindfs. The only reason I'd do anything else given your requirements is if it wasn't available.

If you wanted the scripts to be able to write to the directory tree, but without affecting the actual files, you could use a union filesystem, for example funionfs or unionfs-fuse.

share|improve this answer
+1 Thanks for the thorough answer! – David B Sep 13 '10 at 12:26

There is no real way because no matter what, you'll be always able to delete them in the end.

Still, you could try with file permissions. Right-click on the directory and set folder access to Access files and set file access to read-only. After that click on Apply Permissions to Enclosed Files. This way, you'll have to manually unset this setting when you decide to delete files in that directory.

share|improve this answer
+1 Read-only ACLs is the obvious and cleanest solution. – paradroid Sep 12 '10 at 15:06

You could rsync the directory to another and use --link-dest to create hardlinks so they don't take any extra space.

A good article is Time Machine for every Unix out there.

share|improve this answer

To err is human. I once deleted an important file because I just woke up and I was still sleepy (no hangover) :) Fortunately, it happened long after I learned some tricks that help mitigating the negative impact of such silly actions. Here they are:

  • always make backups, periodically make sure that the backups indeed contain what they are supposed to contain, to avoid the situation when you lose a file, try to restore it from a backup and discover that for some reason it's not contained in the backup
  • use version control
  • use an accounting system like inotify, it will help you track back filesystem changes

From that incident I've set up an additional adamant rule: "Never touch a computer when still sleepy".

share|improve this answer

Your Answer


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.