Operating System - HP-UX
1834717 Members
2224 Online
110069 Solutions
New Discussion

Move file to file.timestamp

 
SOLVED
Go to solution
Rudi Martin
Advisor

Move file to file.timestamp

Hi all

I am busy writing a script but need help with one command to move one file to another file.ddmmyy (which would automatically show the day script is run date)

Thanks
This is what I got so far , but just can't get the context right.

mv /home/mfgdata/BARCODE.326 /home/mfgdata/BARCODE.`date +'%d%m%y'`

This creates the barcode. file and leaves the extension blank.

Thanks
8 REPLIES 8
Stefan Farrelly
Honored Contributor

Re: Move file to file.timestamp

You need this;

touch t.$(date +%d%m%y)
Im from Palmerston North, New Zealand, but somehow ended up in London...
Bill McNAMARA_1
Honored Contributor

Re: Move file to file.timestamp

This works:

touch /tmp/BARCODE.$(date +%d%m%y)
ls -la /tmp/ | grep BARCODE*


Try avoiding the ' and `'s

Later,
Bill
It works for me (tm)
Bill McNAMARA_1
Honored Contributor

Re: Move file to file.timestamp

This works on Linux..

touch /tmp/BARCODE..`date +'%d%m%y'`

ls -la /tmp/ | grep BARCODE*
It works for me (tm)
Vicente Sanchez_3
Respected Contributor

Re: Move file to file.timestamp

Hello,

Get first date into a variable:
var=$(date "+%d%m%y%H%M%S")
then rename the file
mv $OLDFILE $NEWFILE.$var

HTH, Vicente.
Frederic Sevestre
Honored Contributor

Re: Move file to file.timestamp

Hi,

I can't understand your problem.
Your syntax works fine for me ???
#touch FILE.xxx
#mv FILE.xxx FILE.`date +%d%m%y`
#ll FILE.*
-rw-rw-rw- 1 root sys 0 Apr 15 11:05 FILE.150403


Regards,
Fr??d??ric


Crime doesn't pay...does that mean that my job is a crime ?
Steve Steel
Honored Contributor
Solution

Re: Move file to file.timestamp

Hi


using tmp/1

mv tmp/1 tmp/1$(echo "."`date '+%d%m%y%H%M%S'`)

works and also adds hours minutes seconds for a real exact date


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Rudi Martin
Advisor

Re: Move file to file.timestamp

Maybe you guys understood me wrong. The file is already there , every day , called barcode.326. I want to run a cronjob every night to rename the filename to barcode.ddmmyy for that day , so that a barcode.326 is empty for the next day.

Rudi Martin
Advisor

Re: Move file to file.timestamp

Thanks Steve Steel. I used yours and just changed it a bit...

This works perfectly

mv /home/mfgdata/barcode.rud /home/mfgdata/barcode.`date
'+%d%m%y'`

Cheers