繁体   English   中英

权限被拒绝,但文件是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

$()获取括号内的操作结果,并尝试将其作为命令执行。 如果此结果不是可以运行的结果,您将收到各种错误消息。

权限被拒绝即将到来,因为$()任何结果恰好出现在你的机器上也恰好是你无法执行的东西。 在我的脚本测试中,我也得到Is a directorycommand not found 它实际上与hello.txthello1.txt的模式hello1.txt

我应该提一下,我不确定你正在寻找的结果,所以做出上述改变可能会或可能不会得到你想要的。 然而,现在的脚本运行,给你生du导致hello.txt ,善良的,在排序结果hello1.txt 如果您尝试从最小磁盘使用量到最大磁盘使用列表,则可能需要稍微调试排序(提示:尝试从du取消-h )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM