我可以在 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/
但不是我的用户帐户:
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/
我不明白为什么我看不到文件(/media
具有 a+r 权限)。
答案1
为了能够“进入”目录(这是列出其内容的先决条件),您还需要 +x 权限。
还请注意,这是从目录结构顶部(根目录)开始一直的要求。为了能够进入 /foo/bar/baz 目录,用户需要在每个中间目录上都拥有 +x 权限。
答案2
我使用我的pathlld
脚本pathlld
是:
#!/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
它不检测以只读方式挂载的文件系统,因此使用mount
它。