Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, I'm trying to make a script that I'd add to cron that would pack some files in an archive file and prifix the curent date to the filename. Curently ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2006
    Location
    Slovenia
    Posts
    79

    Archive Script


    Hi,

    I'm trying to make a script that I'd add to cron that would pack some files in an archive file and prifix the curent date to the filename.

    Curently this is how it's setup:

    Code:
    tar -c /home/user/archive/filename.tgz /home/user/folder/*.gif /home/user/folder/*.jpg /home/user/folder/*.png
    But I still don't know how to make the archive into a zip file and how to prifix the date into the filename. Something like /home/user/archive/26-11-2006_filename.zip .

    Thanks for the help

  2. #2
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    This information is all available in the man pages for tar and date.

    Code:
    [hector@troy ~]$ date +%d-%m-%Y
    26-11-2006
    Code:
    [hector@troy ~]$ tar czf backup somefile1 
    [hector@troy ~]$ file backup 
    backup: gzip compressed data ...
    Finally, you can simply mv the filename such that it's prefixed with the date. Example: BACKUP1=/some/file1
    DATE1=$(date +%d-%m-%Y)
    mv "$BACKUP1" "$DATE1"_"$BACKUP1"

  3. #3
    Just Joined!
    Join Date
    Apr 2006
    Location
    Slovenia
    Posts
    79
    Cool, thank you >anomie< it works great.

    Thanks again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •