Why Can’t Root Do “ls”?

Something bad happened and my Linux root user couldn’t ls. I’ll show you to the codes:

[root@centos-6 www]# ls
ls: cannot open directory .: Operation not permitted

The first thing I thought is permissions. But wait, I’m root. I own this joint. What is really going on here?

It’s always good to go back to recent events when troubleshooting. Lucky for me, I know what happened shortly before I got this error. I got in a fight with svn and ended up re-checking out my svn repo. That fight with .svn is beyond the scope of this blog post. What I did when I re-checked out my svn repo was effectively create a new directory with the same name in the same place and this upset my terminal. Apparently, two directories with the same path are not equivalent. That’s tough to wrap your mind around because you know that as a directory with a path. Behind the scenes, the OS knows them as inodes.

To fix the issue, simply close out any terminals that reference the old inode. If you want to get fancy, I suppose you could remount the directory. Mounting and remounting is beyond the scope of this blog post.

DO try this at home:

ctrl+a, 0
mkdir /tmp/foo
cd /tmp/foo
ctrl+a, 1
rmdir /tmp/foo
mkdir /tmp/foo
touch /tmp/foo/bar
ctrl+a, 0

Notice how in screen 0 the directory is empty and in screen 1 it contains bar. It really amazes me the things I learn about the deep workings of files in the file business.

SmartFile is a business file mangement platform that gives you more control, compliance and security.