|
|
| Author |
Message |
Jukas
Toomuchtimeonhands

Joined: 19 Mar 2003 Posts: 896
|
Posted: 04/08/06 - 13:06 Post subject: Inserting a datestamp in a filename under linux?
|
|
|
I have several sql databases that I want to dump on a daily basis and backup. No problem, I can setup a simple script/cron job to do it. But I can't for the life of me figure out how to rename a file to include the current datestamp. I know how to do it via a batchfile in Windoze but I can't figure out how to do it via the command line.
For example taking filepoopy.tar.gz and renaming it to filepoopy04082006.tar.gz .
Ideally it would rename the file and then copy the renamed file to a different directory/network share.
Oh, and did I mention I'm lazy and don't know perl?
|
|
|
Back to top
|
|
|
|
 |
motherface
RealPoor Guru

Joined: 12 Mar 2003 Posts: 3407
|
Posted: 04/08/06 - 15:16 Post subject:
|
|
|
$ date '+%Y%m%d';
$ for i in `/bin/ls`; do d=`date '+%Y%m%d'`; mv $i $i$d; done
|
|
|
Back to top
|
|
|
|
 |
motherface
RealPoor Guru

Joined: 12 Mar 2003 Posts: 3407
|
Posted: 04/08/06 - 15:17 Post subject:
|
|
|
|
Also, always put the most significant digit furthest to the left, e.g. YMD rather than MDY or DMY. That way they sort properly.
|
|
|
Back to top
|
|
|
|
 |
Occulis
RealPoor Jedi

Joined: 11 Oct 2002 Posts: 13293
Location: Moral Relativity Central
|
Posted: 04/08/06 - 15:20 Post subject:
|
|
|
I have a 1-line script called 'arcname'. Could do it with an alias but, whatever:
| Code: |
#!/bin/sh
date +%Y.%b.%d_at_%H.%M
|
Then if i want to use it I go:
| Code: |
occ@demon:~> echo "Boy this is wonderful." >> `arcname`-thoughts.txt
occ@demon:~> cat 2006.Apr.08_at_14.08-thoughts.txt
Boy this is wonderful.
|
|
|
|
Back to top
|
|
|
|
 |
motherface
RealPoor Guru

Joined: 12 Mar 2003 Posts: 3407
|
Posted: 04/08/06 - 16:03 Post subject:
|
|
|
|
You could also maybe pipe the file to rotatelogs or cronolog if the app supports piping.
|
|
|
Back to top
|
|
|
|
 |
Lumberg
RealPoor Guru

Joined: 17 Nov 2002 Posts: 4404
Location: i'm in ur base, i'm killin ur dudes
|
Posted: 04/08/06 - 17:31 Post subject:
|
|
|
|
yeah
|
|
|
Back to top
|
|
|
|
 |
Occulis
RealPoor Jedi

Joined: 11 Oct 2002 Posts: 13293
Location: Moral Relativity Central
|
Posted: 04/08/06 - 17:35 Post subject:
|
|
|
|
lumberg, i hate aerosmith, please change your avatar
|
|
|
Back to top
|
|
|
|
 |
motherface
RealPoor Guru

Joined: 12 Mar 2003 Posts: 3407
|
Posted: 04/08/06 - 18:54 Post subject:
|
|
|
| Occulis wrote: | | lumberg, i hate aerosmith, please change your avatar | lawlz
|
|
|
Back to top
|
|
|
|
 |
Lumberg
RealPoor Guru

Joined: 17 Nov 2002 Posts: 4404
Location: i'm in ur base, i'm killin ur dudes
|
Posted: 04/08/06 - 23:58 Post subject:
|
|
|
| Occulis wrote: | | lumberg, i hate aerosmith, please change your avatar |
find me one, baldy
|
|
|
Back to top
|
|
|
|
 |
|
|