user2398188
user2398188

Reputation: 1477

Linux zip command - adding date elements to file name

occasionally I run a backup of my phpbb forum files from the Shell command line:

zip -r forum_backup ~/public_html/forum/*

I'd like to add date elements to the file name, so that the zip file created is automatically formed as

forum_backup_05182013.zip

any other similar current date format would also be acceptable

Upvotes: 2

Views: 6885

Answers (3)

Ry Blaisdell
Ry Blaisdell

Reputation: 11

Without defining a variable first you can do it in one line with

zip -r "forum_backup_$(date +"%Y-%m-%d").zip" filelist

As taken from here

Upvotes: 1

TelKitty
TelKitty

Reputation: 3156

now=$(date +"%m%d%Y")
zip -r forum_backup_$now ~/public_html/forum/

Upvotes: 5

frostyplanet
frostyplanet

Reputation: 98

the following shell command, change the format as you want

FORMAT="%Y%m%d"
_DATE=$(date +"$FORMAT" )
zip -r "forum_bakcup_${_DATE}" ~/public_html/forum/*

Upvotes: 0

Related Questions