I am running Ubuntu 10.04.2 LTS. Why I can't I cd into the /var/www directory?

david@ubuntu:/var$ pwd

david@ubuntu:/var$ ls -l
drwxrwxr-- 13 root root  4096 2011-02-26 21:53 www

david@ubuntu:/var$ cd www
-bash: cd: www: Permission denied

david@ubuntu:/var$ sudo cd www
sudo: cd: command not found
  • 2
    cd is a shell built-in so sudo can't be used. – Dennis Williamson Mar 4 '11 at 14:57
  • And even if it could be used, it would be pointless. There is generally no way to make another process change its working directory, so whatever the cd executable could do, it couldn't change the shell process' cwd. – David Schwartz Aug 20 '11 at 21:12

You need execute permission to cd into a directory.

sudo chmod o+x /var/www
  • 5
    A little bit of clarification: In the example above both root (the user) and root (the group) have the execute bit set. So members of the group root can cd into www. User david cannot cd because he is not included in the root group members. You can inspect that by viewing the contents of /etc/group – adamo Mar 4 '11 at 13:39

There is some reason for prohibiting the ''others'' from entering the directory, no? So I would suggest to get root access to enter that directory, do some stuff, and leave it, dropping the sudo shell.

sudo -i 
cd /var/www
# do your thing
cd -

Just a little further info, it would be wise to create a web user and group for your system and not have services running as root. Then you can also add users to that group if needed and not be giving root privileges out.


Edge case:

It may happen that you are trying to cd into a file. The same message is thrown then. This may happen when something that you think should be a directory, is a file in reality.

  • 1
    Well, Permission denied and Not a directory are different errors, and both describes what's wrong pretty clearly... – Esa Jokinen Jun 22 '20 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.