找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 17981|回复: 2

[问题求助] 无指定文件名条件下的多子目录中文件筛选、剔除shell脚本

[复制链接]
发表于 2012-6-4 16:19:28 | 显示全部楼层 |阅读模式
http://bbs.bathome.net/viewthrea ... p;extra=&page=1

链接地址处是一个在win平台下需要解决的问题,在11#已经得到了完整的解决。
因为涉及到的文件是deb格式,自然想到了linux平台如果发生此类问题该如何解决的问题,
现将链接发布至此,供大家讨论学习。

注:1#和17#两楼的内容加起来后,是一个完整的项目要求。
发表于 2012-7-10 17:29:08 | 显示全部楼层
  1. # 文件夹结构
  2. [seesea@bathome test]$ ls A/
  3. atimetool_1.9.6  atimetool_1.9.7  atimetool_1.9.8
  4. [seesea@bathome test]$ ls A/*/*
  5. A/atimetool_1.9.6:
  6. atimetool_1.9.xxxx.deb
  7. atimetool_1.9.6.deb

  8. A/atimetool_1.9.7:
  9. atimetool_1.9.xxxx.deb
  10. atimetool_1.9.7.deb
  11. atimetool_1.9.6.deb

  12. A/atimetool_1.9.8:
  13. atimetool_1.9.6.deb
  14. # 生成重复列表
  15. [seesea@bathome test]$ for f in A/*/*.deb; do echo ${f##*/}; done | sort | uniq -c | sort -r
  16.       3 atimetool_1.9.6.deb
  17.       2 atimetool_1.9.xxxx.deb
  18.       1 atimetool_1.9.7.deb
  19. # 生成重复列表->文件
  20. [seesea@bathome test]$ for f in A/*/*.deb; do echo ${f##*/}; done | sort | uniq -c | sort -r > result.txt
  21. # 生成操作菜单,根据选择进行操作
  22. [seesea@bathome test]$ select menu in $(awk '{print $2}' result.txt) "QUIT";do if [ "$menu" = "QUIT" ]; then break; fi; rm -rf A/*/$menu; done
  23. 1) atimetool_1.9.6.deb
  24. 2) atimetool_1.9.xxxx.deb
  25. 3) atimetool_1.9.7.deb
  26. 4) QUIT
  27. #? 1
  28. #? 2
  29. #? 3
  30. #? 4
  31. # 删除完文件的结果
  32. [seesea@bathome test]$ ls A/atimetool_1.9.*
  33. A/atimetool_1.9.6:

  34. A/atimetool_1.9.7:

  35. A/atimetool_1.9.8:
复制代码
发表于 2012-11-13 13:05:53 | 显示全部楼层
谢谢分享哈
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-16 23:32 , Processed in 0.016888 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表