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. Commented Mar 4, 2011 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. Commented Aug 20, 2011 at 21:12

5 Answers 5


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
    Commented Mar 4, 2011 at 13:39
  • I never knew you needed the execute permission to cd into a directory, weird. Commented Sep 8, 2021 at 20:45

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... Commented Jun 22, 2020 at 15:17

Are you trying to cd into a home folder?
It might be that you're trying to cd to a path including ~ but it is not being expanded because you're using quotes around it.

$ cd "$root/foo"
bash: cd: ~/myfolder/foo: No such file or directory
$ cd "~"
bash: cd: ~: No such file or directory

There's a very good answer in AskUbuntu explaining in detail that

Any kind of quotation around the ~ prevents this tilde expansion.

So you might be trying to cd $location and it's not working because location includes a tilde.

A good quick solution is to use $HOME instead of ~. While ~ is not expanded even within double-quotes, $HOME is.
So change:

  • From declare location = "~/ExistingFolder/"
  • To declare location = "$HOME/ExistingFolder/"

You should read the original answer in the AskUbuntu question "Why can't I cd to a quoted tilde ('~')?".
It explains in good detail what is happening, and the available options.

  • I know this is unrelated to "Permission denied" in the original question. But I landed in this question with one of the searches for my strange case while I didn't yet understand it, and this question fits in the problem I was searching for: "why can't I cd into somewhere that I expected be able to cd into? not even ls..."
    – ANeves
    Commented Dec 21, 2022 at 9:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .