![使用某些文件或将文件复制到桌面的权限被拒绝](https://linux22.com/image/1114095/%E4%BD%BF%E7%94%A8%E6%9F%90%E4%BA%9B%E6%96%87%E4%BB%B6%E6%88%96%E5%B0%86%E6%96%87%E4%BB%B6%E5%A4%8D%E5%88%B6%E5%88%B0%E6%A1%8C%E9%9D%A2%E7%9A%84%E6%9D%83%E9%99%90%E8%A2%AB%E6%8B%92%E7%BB%9D.png)
前段时间,我在 Ubuntu 12.10 中遇到了一些错误,很多软件都出现了权限被拒绝的错误。最后我找到了解决方案。我发现,当我单击每个文件夹和文件(右键单击,然后单击属性)时,我的系统中的很多文件(包括“主”目录中的文件和文件夹,如“图片”、“桌面”、“音乐”和其他文件夹)在权限选项卡中被设置为“www-data”。因此,一种解决方案是成为 nautilus 中的 root,然后将每个文件或文件夹中的“www-data”更改为“用户名”,但这样做需要很长时间。所以我的问题是,有没有更简单的方法让“用户名”再次成为默认值?
运行此命令后:
find /home/{username} -user www-data | xargs sudo chown {username}
我收到这些错误:
amirrazor@ubuntu:~$ find /home/amirrazor -user www-data | xargs sudo chown amirrazor
xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option
[sudo] password for amirrazor:
chown: cannot access `/home/amirrazor/test': No such file or directory
chown: cannot access `piano.wma': No such file or directory
chown: cannot access `/home/amirrazor/Ubuntu': No such file or directory
chown: cannot access `One/Shared': No such file or directory
chown: cannot access `With': No such file or directory
chown: cannot access `Me': No such file or directory
chown: cannot access `/home/amirrazor/old_Media': No such file or directory
chown: cannot access `Cache_000/f_000003': No such file or directory
chown: cannot access `/home/amirrazor/old_Media': No such file or directory
chown: cannot access `Cache_000/f_000007': No such file or directory
chown: cannot access `/home/amirrazor/old_Media': No such file or directory
chown: cannot access `Cache_000/f_000002': No such file or directory
chown: cannot access `/home/amirrazor/old_Media': No such file or directory
chown: cannot access `Cache_000/data_1': No such file or directory
chown: cannot access `/home/amirrazor/old_Media': No such file or directory
chown: cannot access `Cache_000/f_000004': No such file or directory
chown: cannot access `/home/amirrazor/old_Media': No such file or directory
chown: cannot access `Cache_000/index': No such file or directory
chown: cannot access `/home/amirrazor/old_Media': No such file or directory
chown: cannot access `Cache_000/data_2': No such file or directory
chown: cannot access `/home/amirrazor/old_Media': No such file or directory
chown: cannot access `Cache_000/f_000006': No such file or directory
chown: cannot access `/home/amirrazor/old_Media': No such file or directory
chown: cannot access `Cache_000/f_000001': No such file or directory
chown: cannot access `/home/amirrazor/old_Media': No such file or directory
chown: cannot access `Cache_000/data_3': No such file or directory
chown: cannot access `/home/amirrazor/old_Media': No such file or directory
chown: cannot access `Cache_000/f_000005': No such file or directory
chown: cannot access `/home/amirrazor/old_Media': No such file or directory
chown: cannot access `Cache_000/data_0': No such file or directory
答案1
如果 Bob 想要拥有他的主文件夹中的所有文件:
sudo chown -Rc bob:bob /home/bob
- R 表示递归。
- bob:bob 是 Bob 的用户:组,通常具有相同的名称
主文件夹中的某些系统文件不属于用户所有,但重新启动后可以重新创建它们。
答案2
如果您不担心丢失作为文件所有者的 www-data,那么您可以轻松地在 bash 中执行某些操作。
sudo find /home/{username} -user www-data -exec chown {username} "{}" \;