Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

Given the following directory:

drwx------ 2 joe joe 4096 Jan 11  2010 /home/joe

Is there a way for me as the user root, to avoid accidentally cd-ing into this directory?

I'm not looking for actual permission enforcement, but for some setting (e.g. in the bash shell) that helps the root user avoid such a "private" directory.

share|improve this question
do you employ selinux ? – Sirex Sep 1 '11 at 9:25
Sorry, no SELinux. – unixtippse Sep 1 '11 at 17:54
up vote 3 down vote accepted

There's no way of preventing root from accessing the directory - within a Unix system root is omnipotent.

As to accidentally doing depends on what you are using to access the directory.

You might try....

export PS1="\u@\h [\$(]>

Where is something like...


if [ `whoami` = 'root' -a `pwd` = '/home/joe'] ; then
   echo -n "!!!!!!accessing /home/joe as root !!!!!!!!!"
share|improve this answer
I'm tempted to accept this as the answer, just because of the creativity. :-) What about wrapping cd into a shell alias that checks what's ahead? Handling all the cd use cases (cd, cd -, cd ~, cd ~/foo, cd ~foo/../foo) sounds a bit overkill, though. – unixtippse Sep 1 '11 at 18:01
the cd wrapper alias isn't as hard as you'd think, but it may well break shell scripts if you output a "do you want to continue" type message. – Sirex Sep 2 '11 at 6:44
@Sirex: in addition to unixtippse's list there's 'popd' and others. – symcbean Sep 5 '11 at 9:49

You could write a script inside .bashrc

something like ... if [ command == "cd /home/joe" ] do ask done

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.