问题原文
原帖链接 · Samuel Lui · CC BY-SA 3.0
1. list the files in session dir
$ /var/lib/php/sessions$ sudo ls -la
total 20
drwx-wx-wt 2 root root 12288 May 20 14:26 .
drwxr-xr-x 4 root root 4096 Feb 26 21:15 ..
-rw------- 1 www-data www-data 0 May 20 14:26 sess_716a24lf4tsnmfucpq50uf1pk7
-rw------- 1 www-data www-data 124 May 20 14:26 sess_fkif8ed8k85olh53q9so1cd6s3
-rw------- 1 www-data www-data 0 May 20 14:25 sess_ov6nrn16gg81i44u9angk3bls6
2. sudo delete all files
$ /var/lib/php/sessions$ sudo rm -rf ./*
3. But the session files still existed!
$ /var/lib/php/sessions$ sudo ls -la
total 20
drwx-wx-wt 2 root root 12288 May 20 14:26 .
drwxr-xr-x 4 root root 4096 Feb 26 21:15 ..
-rw------- 1 www-data www-data 0 May 20 14:26 sess_716a24lf4tsnmfucpq50uf1pk7
-rw------- 1 www-data www-data 124 May 20 14:26 sess_fkif8ed8k85olh53q9so1cd6s3
-rw------- 1 www-data www-data 0 May 20 14:25 sess_ov6nrn16gg81i44u9angk3bls6
已采纳解答
原帖链接 · Esa Jokinen · CC BY-SA 3.0
The problem here is that path name expansion occurs BEFORE the sudo. The path name expansion for ./* doesn't have permission to see the directory contents. Therefore, it would not get expanded to rm -rf ./sess_716a24lf4tsnmfucpq50uf1pk7 ./sess_fkif8ed8k85olh53q9so1cd6s3 ./sess_ov6nrn16gg81i44u9angk3bls6 as supposed – and as it would, if the whole command was run as root.
You can launch a new terminal inside sudo. Try:
sudo sh -c "rm -rf /var/lib/php/sessions/*"
Notice that I used the full path because it's much more safe than a relative path. Once a colleague typed / instead of ./ inside sudo rm -rf. You can imagine what happened: unnecessary restoring task for me... and one user less in the sudoers list.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
