3:58 pm on Feb. 15, 2006 (utc 0)


MattyMoose gave me some great advice a while back when I was trying to automate a backup process, the result being the following command:

find ./ -name "*.txt" -print ¦ tar czf archive/db_022006.tar.gz -T - && find ./ -name "*.txt" -exec rm {} \;

Well now I want to take it a bit further so that the tar will be created and named according to the current date. So, I got the current date using:
date '+%d%m%Y'

But how can I put this into the backup command above?

I tried:

find ./ -name "*.txt" -print ¦ tar czf date '+archive/db_%d%m%Y.tar.gz' -T - && find ./ -name "*.txt" -exec rm {} \;

But unfortunately that didn't work. Anyone got a sokution they could share?

Many thanks


 6:51 pm on Feb. 15, 2006 (utc 0)

Using your first example there …

find ./ -name "*.txt" -print ¦ tar czf archive/db_022006$(date '+%F_%H%I%S%P').tar.gz -T - && find ./ -name "*.txt" -exec rm {} \;


 7:13 pm on Feb. 15, 2006 (utc 0)

Cheers Coopster,

I had tried a couple of bracket combinations, didn't know about the $ in front though - is there a good reference for this sort of thing somewhere? Coming from a Windows environment its quite a steep learning curve, that said I'm already finding you can do so much with just a single line command.

Many thanks


 6:47 am on Feb. 21, 2006 (utc 0)

Hi there!

Same idea as what coopster said, just I prefer to be able to reuse the date variable throughout my script, so I usually define something like this:


date=`date '+%d%m%Y'`

… do stuff …

find ./ -name "*.txt" -print ¦ tar czf date '+archive/db_${date}.tar.gz' -T - && find ./ -name "*.txt" -exec rm {} \;

Then that way you can re-use the date variable.

I can't seem to find the bookmark I had that I used as reference for shell scripting, but give this a try, or search around a bit, find a format that you like. 🙂


파일명에 date가 삽입된 tar 파일 만들기

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다