免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1672 | 回复: 4
打印 上一主题 下一主题

请教将文件按规则打包(tar)的方法 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-04-06 13:25 |只看该作者 |倒序浏览
请教各位老大,比如说,ls的输出如下:

-rw-r--r--   1 oracle     dba         226385 Apr  6 12:59 sp_257_258_0002_20050328.lst
-rw-r--r--   1 oracle     dba         217712 Apr  6 12:59 sp_258_259_0100_20050328.lst
-rw-r--r--   1 oracle     dba         213661 Apr  6 12:59 sp_259_260_0200_20050328.lst
-rw-r--r--   1 oracle     dba         246377 Apr  6 12:49 sp_348_349_1900_20050331.lst
-rw-r--r--   1 oracle     dba         243480 Apr  6 12:49 sp_349_350_2000_20050331.lst
-rw-r--r--   1 oracle     dba         246239 Apr  6 12:49 sp_350_351_2100_20050331.lst
-rw-r--r--   1 oracle     dba         247652 Apr  6 12:49 sp_351_352_2200_20050331.lst
-rw-r--r--   1 oracle     dba         246034 Apr  6 12:49 sp_352_353_2300_20050331.lst
-rw-r--r--   1 oracle     dba           4837 Apr  6 13:01 sp_379_380_1000_20050401.lst
-rw-r--r--   1 oracle     dba           3746 Apr  6 13:01 sp_381_382_1034_20050401.lst
-rw-r--r--   1 oracle     dba           3746 Apr  6 13:01 sp_382_383_1100_20050401.lst
-rw-r--r--   1 oracle     dba           3746 Apr  6 13:01 sp_383_384_1200_20050401.lst
-rw-r--r--   1 oracle     dba           3746 Apr  6 13:01 sp_384_385_1300_20050401.lst
-rw-r--r--   1 oracle     dba           3746 Apr  6 13:01 sp_385_386_1400_20050401.lst
-rw-r--r--   1 oracle     dba           3746 Apr  6 13:01 sp_386_387_1500_20050401.lst

。。。


现在想写个脚本,每天把前一天的sp_开头的文件做成tar,不知道可是做到这里就坐不下去了,请各位大师帮帮忙:

ls -l | awk '{print $9}'|sed -n '/20050401/p'
输出如下:
sp_257_258_0002_20050328.lst            
sp_258_259_0100_20050328.lst            
sp_259_260_0200_20050328.lst            
sp_348_349_1900_20050331.lst            
sp_349_350_2000_20050331.lst            
sp_350_351_2100_20050331.lst            
sp_351_352_2200_20050331.lst            
sp_352_353_2300_20050331.lst            
sp_379_380_1000_20050401.lst            
sp_381_382_1034_20050401.lst            
sp_382_383_1100_20050401.lst            
sp_383_384_1200_20050401.lst            
sp_384_385_1300_20050401.lst            
sp_385_386_1400_20050401.lst            
sp_386_387_1500_20050401.lst            


请注意,不能使用find 按天查找的方法,因为有可能我按照字符串'20050328'做tar文件,而不是严格按照实际的日期。

论坛徽章:
0
2 [报告]
发表于 2005-04-06 15:35 |只看该作者

请教将文件按规则打包(tar)的方法

要求好像比较少,不知道符合你的要求吗
[kennyyu@haha 20050406]$ ls
sp_257_258_0002_20050328.lst  sp_257_258_0100_20050328.lst  sp_257_258_0190_20050328.lst  sp_257_258_0190_20050329.lst
  1. [kennyyu@haha 20050406]$ tar -cvf sp_20050328.tar `ls|grep "20050328"`
  2. sp_257_258_0002_20050328.lst
  3. sp_257_258_0100_20050328.lst
  4. sp_257_258_0190_20050328.lst
复制代码

[kennyyu@haha 20050406]$ tar -tf sp_20050328.tar
sp_257_258_0002_20050328.lst
sp_257_258_0100_20050328.lst
sp_257_258_0190_20050328.lst

论坛徽章:
0
3 [报告]
发表于 2005-04-07 15:29 |只看该作者

请教将文件按规则打包(tar)的方法

多谢 精灵网

不过,还有一个问题,如果我只想将“昨天”的sp_开头的文件打包怎么办?(不是说昨天生成的文件,而是sp文件名中的日期是昨天的,比如今天是20050407,那么我需要20050406)

多谢了。

论坛徽章:
0
4 [报告]
发表于 2005-04-08 10:49 |只看该作者

请教将文件按规则打包(tar)的方法

up

论坛徽章:
0
5 [报告]
发表于 2005-04-08 12:31 |只看该作者

请教将文件按规则打包(tar)的方法

你的是什么系统?
在RH linux 9.0下可以用:
date -d "1 day ago" +"%Y%m%d"
来得到昨天的时间。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP