如何将旧文件移动到另一个文件夹 [英] How to move old file to another folder

查看:157
本文介绍了如何将旧文件移动到另一个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的文件夹中,我有一个后缀为创建该文件的日期的文件,例如: file.log2012-08-21,file.log2012-08-20 ...现在如何移动早于2012-08-20的文件?我知道我每天如何做:mv file.log2012-08-19 /old/,但我不知道何时停止... mv命令中是否有一些参数可以使此操作更容易?

in my folder I have file which suffix is date when this file was created for example: file.log2012-08-21, file.log2012-08-20 ... Now how I can move file which is older then 2012-08-20 ? I know how I can do this day by day: mv file.log2012-08-19 /old/ but I dont know when to stop ... is there some parameter in command mv to do this easier ?

推荐答案

ls -l | awk '{print $NF}' | awk 'substr($0, length($0)-9, length($0)) < "2012-08-20" {system("mv "$0" /old/")}'

这会将所有早于"2012-08-20"的文件移至文件夹"/old".同样,您可以更改"2012-08-20"以指定所需的特定日期.请注意,这假设文件后缀是日期戳,但前缀可以是任何名称.

This will move all the files older than "2012-08-20" to the folder "/old". Likewise, you can change the "2012-08-20" to specify particular date you want. Note this assumes that the file suffix is a date stamp, but the prefix can be any name.

如果您只需要将文件移到特定日期之前,那么我认为rkyser的答案会更好.

If you just need to move files older than a certain days, then I think rkyser's answer is better for that.

这篇关于如何将旧文件移动到另一个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆