Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am able to list directories in a root shell,

root@ThinkPad:~# ll /media/
total 36
drwxr--r--  6 root root  4096 2011-05-12 16:41 ./
drwxr-xr-x 22 root root  4096 2011-05-12 13:14 ../
drwxr-xr-x  5 root root  4096 2011-05-12 15:56 hd/
drwxr--r--  2 root root 16384 2011-05-12 14:20 lost+found/
drwxr-xr-x  5 root root  4096 2011-05-12 16:34 main/
drwxr--r--  4 root root  4096 2011-05-12 16:41 .Trash-0/

but not from my user account:

alex@ThinkPad:~$ ll /media/
ls: cannot access /media/..: Permission denied
ls: cannot access /media/hd: Permission denied
ls: cannot access /media/lost+found: Permission denied
ls: cannot access /media/.Trash-0: Permission denied
ls: cannot access /media/.: Permission denied
ls: cannot access /media/main: Permission denied
total 0
d????????? ? ? ? ?                ? ./
d????????? ? ? ? ?                ? ../
d????????? ? ? ? ?                ? hd/
d????????? ? ? ? ?                ? lost+found/
d????????? ? ? ? ?                ? main/
d????????? ? ? ? ?                ? .Trash-0/

I don't understand why I can't see files (/media has a+r permission).

share|improve this question

2 Answers 2

up vote 10 down vote accepted

To be able to "enter" a directory, which is kind of a prerequisite for listing its content, you also need the +x permission.

Also note that this is a requirement all the way from the top (root) of the directory structure. To be able to enter a /foo/bar/baz directory a user needs to have the +x permission on every single intermediate directory.

share|improve this answer

I use my pathlld script. pathlld is:

#!/bin/bash
# Show the permissions on all the directories leading from / to
# the parameter.
# Usage: $0 <file_or_dir> <...>
#
#   $Header: /home/walt/bin/RCS/pathlld,v 1.4 2010/02/21 20:34:16 walt Exp $
#
#
function pathlld ()
{
    if [ "$1" = "/" ] ; then
    /bin/ls -ld /
    else
    parent="${1%/*}"
    pathlld "${parent:-/}"
    /bin/ls -ld "$1"
    fi
}
force=0
if [ "$1" = "-f" ] ; then
    force=1
    shift
fi
# Make sure we got at least one filename or directory name
file_or_dir="$1"
file_or_dir="${file_or_dir:?'missing.'}"

while [ $# -ne 0 ] ; do
    if [ $force -eq 1 -o -e "$1" ] ; then
    case "$1" in
        /* ) target="$1" ;;
        *  ) target="$PWD/$1" ;;
    esac
    pathlld "$target"
    [ -L "$target" ] && /bin/ls -ldL "$target"
    else
    echo "Nonexistent file or directory: $1"
    fi
    shift
done

It doesn't detect filesystems mounted read-only, use mount for that.

share|improve this answer

Your Answer

 
discard

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.