Computing.Net > Forums > Solaris > unique name on mv based on date?

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

unique name on mv based on date?

Reply to Message Icon

Original Message
Name: jkeese
Date: August 26, 2003 at 20:01:43 Pacific
Subject: unique name on mv based on date?
OS: solaris8
CPU/Ram: 8g
Comment:

How would you do something like this:
--
mv filename (date +%m%d%y_%M%S)
--
So that the input filename would be given a unique name based on the date and time.
Thanks.


Report Offensive Message For Removal


Response Number 1
Name: David Perry
Date: August 27, 2003 at 02:59:20 Pacific
Reply:

mv filename `date +%m%d%y_%M%S`

This has a resolution of seconds and may not provide a unique name by itself. If this were part of a larger script with a loop it is very possible you would try to name several files the same name which would end up with files being overwritten and deleted. Also it is easier to sort on a date if the most significant value comes first. CCYYMMDD_H:M:S


Report Offensive Follow Up For Removal

Response Number 2
Name: jkeese
Date: August 27, 2003 at 07:06:02 Pacific
Reply:

Hi David,
--
This will be a file that the user uploads to the system once per week. They can only upload one at a time, so 1 second will keep it unique. Your sort is a good idea.
--
--
When I do this, I get a file named literally:
--
date +%y%m%d_%H%M%S
--
--
It does not get the date. I'm using the korn shell.
--
Thanks,

Jim.


Report Offensive Follow Up For Removal

Response Number 3
Name: David Perry
Date: August 27, 2003 at 07:30:54 Pacific
Reply:

Be certain to use the back ticks ( usually near the tilde character ) and not single quotes.

mv filename `date +%Y%m%d_%T`

The ksh also supports this form:

mv filename $(date +%Y%m%d_%T)

man strftime for more details.


Report Offensive Follow Up For Removal

Response Number 4
Name: jkeese
Date: August 27, 2003 at 08:56:41 Pacific
Reply:

Hi David,

That did it!

Thanks a lot for the help.

Jim.


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Solaris Forum Home



Results for: unique name on mv based on date?

DNS domain name on Wireless Network
    Summary: I am trying to get my network card setup on my laptop, but I am having problems figuring out the DNS server name. I use a wireless access point to connect (by ethernet cable) to a free access point. T...
www.computing.net/answers/solaris/dns-domain-name-on-wireless-network/4498.html

Installing USB DSL on Solaris8
    Summary: How can I setup my Solaris box to use with TWCNYC RoadRunner's cable modem service? TWCNYC uses DOCSIS certified cable modem. Coax cable coming from outside is hooked on to the Cable Modem and the...
www.computing.net/answers/solaris/installing-usb-dsl-on-solaris8/3149.html

question on
    Summary: here is something helpful from sun on the subject.....(a little long) I HOPE SUN DOES not COME AFTER ME....:-( To simply zero out the two files do the following: * In the Bourne or Korn shell: ...
www.computing.net/answers/solaris/question-on-/3539.html








Which MP3 player do you have?

iPod/iPhone
Zune
Something Else
None


View Results

Poll Finishes Today.
Discuss in The Lounge
Poll History






Data Recovery Software