访问和重命名目录需要什么样的权限?

时间:2017-03-28 10:08:55

标签: shell permissions

在x,w,r中,访问和重命名目录需要哪个权限。 (我将分别使用cd和mv)

1 个答案:

答案 0 :(得分:1)

请注意,对于mv,您还需要修改(w)当前目录的权限,因为它有效地将新内容(新名称)写入其中..

演示:

testdir="./$0.$$"
pwd="$(pwd)"
err()(echo "$@">&2; return 1)

echo "creating $testdir"
mkdir "$testdir" || err "can't mkdir $testdir" || exit 1
ls -la "$testdir"

trap 'cd "$pwd"; chmod 777 "$testdir"; rm -rf "$testdir"; exit' 0 1 2 15

#ensure the 'w' for the demo
chmod 755 "$testdir"

echo "Cd to $testdir"
cd "$testdir" || err "Can't cd to $testdir" || exit 1

echo "mkdir a"
mkdir a || err "Can't mkdir a" || exit 1
ls -la

echo renaming a to b
mv a b || err "can't rename a to b" || exit 1
ls -la

echo "rewoke 'w' permission from the $testdir (now .)"
chmod 555 . || err "can't chmod 555 ." || exit 1
ls -la

echo trying to rename b to c
mv b c || err "can't rename b to c - this failed"
ls -la