ksh :需要快速可靠地删除多个目录
我有很多目录,需要以最短的时间定期删除它们。 另外,对于每个目录的删除状态需要知道,即是否删除成功。 我需要写在 ksh 上。你能帮我一下吗?
我正在使用的示例代码(我尝试在后台启动 rm-rf)无法正常工作。
for var1 in 1...10
rm -rf <DIR> &
pid[var1]=$!
done
my_var=1
for my_var in 1...var1
wait $pid[my_var]
if [ $? -eq 1 ]
then
echo falied
else
echo passed
fi
done
I have many directories and need to delete them periodically with minimum time.
Additionally for each directories delete status need to know i.e whether deleted successfully or not.
I need to write on the ksh . Could you please help me out.
The sample code which I am using, in which I tried launching rm-rf
in the background, is not working.
for var1 in 1...10
rm -rf <DIR> &
pid[var1]=$!
done
my_var=1
for my_var in 1...var1
wait $pid[my_var]
if [ $? -eq 1 ]
then
echo falied
else
echo passed
fi
done
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你运气不好。 这里的瓶颈是文件系统,并且您不太可能找到一个并行执行原子操作(如目录删除)的文件系统。无论对 shell 代码进行多少修改,都不会让操作系统或文件系统更快地完成其工作。只有一张磁盘,如果每次删除都需要写入磁盘,速度会很慢。
最好的选择是切换到可以快速删除的日志文件系统。我很幸运地使用 XFS 快速删除了大文件(10-40GB),但我还没有尝试过删除目录。无论如何,提高性能的途径在于找到正确的文件系统,而不是正确的 shell 脚本。
You are out of luck. The bottleneck here is the filesystem, and you are very unlikely to find a filesystem that performs atomic operations (like directory deletion) in parallel. No amount of fiddling with shell code is going to make the OS or the filesystem do its job faster. There is only one disk, and if every deletion requires a write to disk, it is going to be slow.
Your best bet is to switch to a journaling filesystem that does deletions quickly. I have had good luck with XFS deleting large files (10-40GB) quickly, but I have not tried deleting directories. In any case, your path to improved performance lies in finding the right filesystem, not the right shell script.
这通常是您的脚本应采用的形式,并对语法中的严重错误进行更正。然而,正如诺曼指出的那样,它不会做你想做的事。另外,
wait
不会像您预期的那样在循环中工作。This is generally the form that your script should take, with corrections for the serious errors in syntax. However, as Norman noted, it's not going to do what you want. Also,
wait
isn't going to work in a loop like you seem to intend.