PowerRC's Blog

Posted by:
PowerRC

该同志还没添加个人介绍

2,125

to move yesterday’s files into a new folder in freebsd/unix

After googling a lot , I think I should share this script.
The purpose of this script is , to move yesterday 's files , into a new folder , which is named by date.
But due to the some difference between linux and freebsd/unix.
The parameters of date ,"-d" can't be used in linux ; and The parameters of xargs , -i can't be used either.


1
2
3
4
5
6
7
8
#!/bin/bash
basePath=/target_path/
yYear=`TZ=GMT+29 date +%Y`
yMonth=`TZ=GMT+29 date +%m`
yDay=`TZ=GMT+29 date +%d`
mkdir -p $basePath$yYear/$yMonth/$yDay/
find $basePath -name "$yYear-$yMonth-$yDay*" -exec mv {} $basePath$yYear/$yMonth
/$yDay/ \;

About this script:
1.Files I need to move , are named with date , like "2013-10-08-xxxxxx" , so my script could only handle this kind of name.
2."TZ=GMT+29" is used to specify the timezone actually.I am in -5 zone , so I set it to +29 , so that I could get the date of yesterday. If you are in +15 , then you should set it to +9.
3.The -exec of find in freebsd/unix is a little bit different , so be careful with it. The end of the script must be "\;" , I tried "\+" but doesn't work.

版权申明

若文中未注明,则本文由 PowerRC 原创,转载请注明出处。

分享

Leave a Reply

*

code

back up ↑