Can't cd into my own directory?

23,765

Solution 1

You need the execute bit set on directories if you want to be able to switch to that. (The filesystem type doesn't really matter.)

chmod u+x ./apache

Solution 2

http://www.albany.edu/faculty/gms/homepage101/unix_permissions.html says

TABLE 1. UNIX DIRECTORY Permissions

WHO                     WHAT THE PERMISSIONS ALLOW
USER   Read (r)         The account owner can list the files in the directory.
       Write (w)        The account owner can create or delete files in the 
                        directory.
       Execute (x)      access files in that directory by name (such as Web 
                        page files).

GROUP  Read (r)         Everyone in the designated group can list the files in 
                        the directory.
       Write (w)        Everyone in the group can create or delete files in the 
                        directory.
       Execute (x)      Everyone in the group can change (cd) into the 
                        directory and access files in that directory by name 
                        (such as Web page files).

OTHER  Read (r)         Anyone can list the files in the directory.
       Write (w)        Anyone can create or delete files in the directory.
       Execute (x)      Anyone can change (cd) into the directory and access 
                        files in that directory by name 
                        (such as Web page files).

The Wikipedia article is worth reading and says

The effect of setting the permissions on a directory (rather than a file) is "one of the most frequently misunderstood file permission issues" (Hatch 2003).

Share:
23,765
Felix
Author by

Felix

I write code.

Updated on September 18, 2022

Comments

  • Felix
    Felix over 1 year

    On an EC2 instance I have changed Apache's log location to a different directory than the default. This is so that I can hold the logs on a (non-boot, only data) EBS.

    However, I can't cd into the logs directory. It belongs to my user and has read permissions for everyone. I can't cat the logs either (although with sudo it works and I can see that Apache is logging just fine).

    $ ls -lh
    total 4.0K
    drw-rw-rw- 2 ubuntu ubuntu 4.0K 2011-05-15 14:52 apache
    $ ls -lh apache/
    ls: cannot access apache/error.log: Permission denied
    ls: cannot access apache/access.log: Permission denied
    total 0
    -????????? ? ? ? ?                ? access.log
    -????????? ? ? ? ?                ? error.log
    $ cd apache
    -bash: cd: apache: Permission denied
    $ sudo ls -lh apache/
    total 2.4M
    -rw-r--r-- 1 ubuntu ubuntu 2.4M 2011-05-15 15:04 access.log
    -rw-r--r-- 1 ubuntu ubuntu  27K 2011-05-15 15:00 error.log
    

    This does not make any sense to me. Help?

    Edit: the filesystem is ext4.

  • AJP
    AJP almost 11 years
    So you have to have execute permissions to cd into a directory? @RedGrittyBrick
  • Blacklight Shining
    Blacklight Shining over 10 years
    Yes, you need execute permission on a directory to “traverse” it—that is, to do anything with its contents. If you do not have execute permission, you can still see the directory, and you can stat it, but you can't ls it or access its contents at all.