linux – 用于删除小于x kb的文件的Shell脚本

linux – 用于删除小于x kb的文件的Shell脚本,第1张

概述我试图找出如何编写一个小脚本来删除小于50千字节的文本文件,但我没有成功. 我的尝试看起来像这样: #!/bin/bashfor i in *.txtdo if [ stat -c %s < 5 ] then rm $i fidone 我会赞美一些指导,谢谢! 您应该使用fedorqui的版本,但供参考: #!/bin/bashfor i in ./*.txt 我试图找出如何编写一个小脚本来删除小于50千字节的文本文件,但我没有成功.

@H_301_8@

我的尝试看起来像这样:@H_301_8@

@H_301_8@

#!/bin/bashfor i in *.txtdo   if [ stat -c %s < 5 ]   then     rm $i   fidone

我会赞美一些指导,谢谢!@H_301_8@解决方法 您应该使用fedorqui的版本,但供参考:

@H_301_8@

@H_301_8@

#!/bin/bashfor i in ./*.txt   # ./ avoIDs some edge cases when files start with dashesdo  # $(..) can be used to get the output of a command  # use -le,not <,for comparing numbers  # 5 != 50k  if [ "$(stat -c %s "$i")" -le 50000 ]  then    rm "$i"  # specify the file to delete        fi # end the if statementdone

通常更容易编写一个程序并验证每个部分是否正常工作,而不是编写整个程序然后尝试调试它.@H_301_8@ 总结

以上是内存溢出为你收集整理的linux – 用于删除小于x kb的文件的Shell脚本全部内容,希望文章能够帮你解决linux – 用于删除小于x kb的文件的Shell脚本所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/1021537.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存