权限被拒绝,尽管文件是 chmod 777
Permission denied, though files are chmod 777
这是我的代码:
#!/bin/sh
sudo touch /home/test/hello.txt
sudo chmod 777 /home/test/hello.txt
sudo touch /home/test/hello1.txt
sudo chmod 777 /home/test/hello1.txt
"$(sudo du -hs /home/test/*)" >> /home/test/hello.txt
"$(sudo sort -n /home/test/hello.txt)" >> /home/test/hello1.txt
head -3 /home/test/hello1.txt
第 7 行报错:权限被拒绝。
我已经将这两个文件都设置为 chmod 777,所以我不知道它是从哪里来的。
感谢您的任何建议!
从 du
和 sort
行中删除 $()
,使它们像这样:
sudo du -hs /home/test/* >> /home/test/hello.txt
sudo sort -n /home/test/hello.txt >> /home/test/hello1.txt
$()
获取括号内的操作结果,并尝试将其作为命令执行。如果此结果不是 运行.
,您将收到各种错误消息
Permission denied 即将出现,因为无论 $()
中的结果恰好在您的计算机上,也恰好是您无法执行的结果。在我对您的脚本的测试中,我还得到了 Is a directory
和 command not found
。真的和hello.txt
或hello1.txt
.
的模式无关
我应该提一下,我不能完全确定您正在寻找的结果,因此进行上述更改可能会或可能不会让您得到您想要的结果。但是,该脚本现在将 运行,为您提供 hello.txt
中的原始 du
结果和 hello1.txt
中的排序结果。如果您尝试获取从最小磁盘使用量到最大磁盘使用量的列表,您可能需要稍微调试排序(提示:尝试从 du
中删除 -h
)。
这是我的代码:
#!/bin/sh
sudo touch /home/test/hello.txt
sudo chmod 777 /home/test/hello.txt
sudo touch /home/test/hello1.txt
sudo chmod 777 /home/test/hello1.txt
"$(sudo du -hs /home/test/*)" >> /home/test/hello.txt
"$(sudo sort -n /home/test/hello.txt)" >> /home/test/hello1.txt
head -3 /home/test/hello1.txt
第 7 行报错:权限被拒绝。 我已经将这两个文件都设置为 chmod 777,所以我不知道它是从哪里来的。
感谢您的任何建议!
从 du
和 sort
行中删除 $()
,使它们像这样:
sudo du -hs /home/test/* >> /home/test/hello.txt
sudo sort -n /home/test/hello.txt >> /home/test/hello1.txt
$()
获取括号内的操作结果,并尝试将其作为命令执行。如果此结果不是 运行.
Permission denied 即将出现,因为无论 $()
中的结果恰好在您的计算机上,也恰好是您无法执行的结果。在我对您的脚本的测试中,我还得到了 Is a directory
和 command not found
。真的和hello.txt
或hello1.txt
.
我应该提一下,我不能完全确定您正在寻找的结果,因此进行上述更改可能会或可能不会让您得到您想要的结果。但是,该脚本现在将 运行,为您提供 hello.txt
中的原始 du
结果和 hello1.txt
中的排序结果。如果您尝试获取从最小磁盘使用量到最大磁盘使用量的列表,您可能需要稍微调试排序(提示:尝试从 du
中删除 -h
)。