Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I frequently need to create datestamped archives.

Here is a one-line example, given two parameters. $1 is the archive name prefix and $2 is the directory to archive.

  tar -cvzf ${1}-$(date +%Y%m%d-%H%M).tar.gz $2
Note, if $2 contains path information (such as absolute path), that path will be stored in the tar. So it is usually used with the working dir as the parent of $2.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: