Server Fault is a question and answer site for system and network administrators. 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 have some hosting on a Linux server and I have a few folders that I don't ever want to delete. There are sub folders within these that I do want to delete.

How do I set the CHMOD permissions on the folders I don't want to delete?

Of course, when I say "I don't ever want to delete" - what I mean is that the end customer shouldn't delete them by accident, via FTP or in a PHP script etc.

As an example of directory structure...


I don't want "MainFolder" to be accidentally deleted, but I'm happy for "SubFolder" and "Another" to be removed!

share|improve this question

migrated from Mar 23 '10 at 10:53

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

up vote 8 down vote accepted

Deleting a file/directory changes the contents of the parent directory, hence, if you don't want MainFolder to be deleted, you want to ensure that the intended user does not have write access to the parent dir of MainFolder.

Assuming this structure: /some/dir/ParentDir/MainFolder/SubFolder

You'll want to run something like this to prevent deletion (for all users):

chmod a-w /some/dir/ParentDir

Of course, this is not an ideal situation as making it non-writeable means than users cannot add additional files/directories to /some/dir/ParentDir

Would a sticky bit fit your purpose better? setting the sticky bit on the parent directory will only allow deletion by the directory owner.

chmod +t /some/dir/ParentDir

Look at the usage section on for more information about Sticky bits.

share|improve this answer
I think I'm going to be lucky with my directory structure - I have a "ParentDir" that essentially contains lots of "MainFolders" that I don't want deleted. Any user-interaction then happens in the next level down. Awesome! I'll try it now! – Sohnee Mar 23 '10 at 11:03

You could change the owner of MainFolder with chown

share|improve this answer
Still doesn't stop someone from deleting it, as that's governed by the parent directory. – Vatine Mar 23 '10 at 11:54

As Oli says, you can chown -R new_owner Mainfolder to ensure all the subdirectories have a different owner to the one that'll be accessing it. That should stop other users deleting it.

To allow other users to access it, you can also create a group and change the file group with chgrp. That way, any members of your "customers" group can access the folders. The alternative is to set the other bit to read if you want everyone to have access.

Note that chmod -R / chown -R / chgrp -R / chcon -R set permissions recursively.

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.