Using system date-time as file name

Using system date-time as file name

Post by Mike Murp » Tue, 03 Feb 1998 04:00:00



Hi:

Could one of you Unix wizards help me here.  What Unix commands does one
use to use the system date-time as a filename via a shell script?  I am
using AIX.

Thanks for any assistance you can provide.

Michael Murphy
===================================================================

            "Distribution & Commerce Systems Solutions"              
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 
 
 

Using system date-time as file name

Post by Gary Gapinsk » Wed, 04 Feb 1998 04:00:00


Hello, Mike:

I usually use something like

filename=xxx.`date '+%Y%m%d%H%M%S'`
touch ${filename}

Check the date or strftime man pages for the various formats for time
components.

Regards,

Gary

 
 
 

Using system date-time as file name

Post by Juergen Ils » Wed, 04 Feb 1998 04:00:00


Hello,


: Hi:
: Could one of you Unix wizards help me here.  What Unix commands does one
: use to use the system date-time as a filename via a shell script?  I am
: using AIX.

To get the current date and time, you can simply use the command "date".
To use the output from date as commandline-parameter for further commands,
you may use some features of the shell, for example:

#!/bin/sh
# this script is an example, that creates a new file (if it does not exist)
# which name constists of the current year, month, date and time...

FILENAME=`date +%y%m%d%H%M`

echo creating file $FILENAME
touch $FILENAME

# end of script

hope, that helps,
ciao,

 
 
 

Using system date-time as file name

Post by Michael Roede » Sat, 07 Feb 1998 04:00:00



> Hi:

> Could one of you Unix wizards help me here.  What Unix commands does one
> use to use the system date-time as a filename via a shell script?  I am
> using AIX.

> Thanks for any assistance you can provide.

> Michael Murphy
> ========

Assuming you're using Korn shell...

I set an environment variable called 'date' like this:

date=`date +"%m%d%y"` (or date +"%d%m%y" for all of you not in the US).

then, $date has 020698 as its value. You can, of course use the date command
in ticks at the time you set the filename instead of setting it as a
variable-- I just think it is more readable in the code. I believe I got
this information from the date man page entry.

Mike

 
 
 

Using system date-time as file name

Post by Bill H » Sat, 07 Feb 1998 04:00:00



>Hi:

>Could one of you Unix wizards help me here.  What Unix commands does one
>use to use the system date-time as a filename via a shell script?  I am
>using AIX.

Try :

# man date

.sig beta testers needed.

 
 
 

Using system date-time as file name

Post by Mike Kleima » Sun, 08 Feb 1998 04:00:00


Well it ain't pretty (the filename that is) but you could just use command
substitution with the date command i.e.

                $ls
                   myfile

                $cat myfile > `date`

                $ls
                  myfile
                  Sat Feb  7 14:20:31 EST 1998

You now have a file called "Sat Feb  7 14:20:31 EST 1998". Of course you
could use some of the date's formatting options to clean it up a bit.

Mike Kleiman




> >Hi:

> >Could one of you Unix wizards help me here.  What Unix commands does one
> >use to use the system date-time as a filename via a shell script?  I am
> >using AIX.

> Try :

> # man date

> .sig beta testers needed.

 
 
 

Using system date-time as file name

Post by William Juli » Sun, 08 Feb 1998 04:00:00




Quote:> Well it ain't pretty (the filename that is) but you could just use command
> substitution with the date command i.e.

>            $ls
>               myfile

>            $cat myfile > `date`

>            $ls
>              myfile
>              Sat Feb  7 14:20:31 EST 1998

> You now have a file called "Sat Feb  7 14:20:31 EST 1998". Of course you
> could use some of the date's formatting options to clean it up a bit.

Eeeeu -- spaces in a file name are a terrible choice! If you really
want to use the default date output, substitute the spaces with something
which you can use later in regular expression matches. eg:

-->date | sed -e 's/ \{1,\}/-/g'
Sat-Feb-7-15:03:56-PST-1998

--
         _,'|            _.-''``-...___..--';
        /, \'.      _..-' ,      ,--...--'''

        `-,;'              ;   ; ; http://www.catmanor.com/moonbeam/
  __...--''     __...--_..'  .;.'  vi is my shepherd; i shall not font.
 (,__....----'''      (,..--''    
perl -e 'print $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'

 
 
 

Using system date-time as file name

Post by Tony Porcz » Sun, 08 Feb 1998 04:00:00




>> Hi: Could one of you Unix wizards help me here.  What Unix commands
>> does one use to use the system date-time as a filename via a shell
>> script?  I am using AIX.
>Well it ain't pretty (the filename that is) but you could just use command
>substitution with the date command i.e.
>            $ls
>               myfile
>            $cat myfile > `date`
>            $ls
>              myfile
>              Sat Feb  7 14:20:31 EST 1998

Ouch... ugly and with spaces...  what's wrong with:

date "+%y%m%d%H%M"

That would produce an easily sortable filename of:

9802071935

If you called that script 'fdate', then you could say:

$ mv myfile `fdate`

or, if you were just beginning to edit the file with vi, you could say:

$ vi `fdate`

t.
---------------------------------------------------------------------

GIT/ED d++(!d) s++:++ a? C++++ USB++++$ P+ E- W(--) N++ !k w--- M- V?

---------------------------------------------------------------------

 
 
 

Using system date-time as file name

Post by Raymond SCHM » Mon, 09 Feb 1998 04:00:00


On Fri, 06 Feb 1998 14:05:51 -0600, Michael Roeder



>> Hi:

>> Could one of you Unix wizards help me here.  What Unix commands does one
>> use to use the system date-time as a filename via a shell script?  I am
>> using AIX.

>> Thanks for any assistance you can provide.

>> Michael Murphy
>> ========

>Assuming you're using Korn shell...

>I set an environment variable called 'date' like this:

>date=`date +"%m%d%y"` (or date +"%d%m%y" for all of you not in the US).

>then, $date has 020698 as its value. You can, of course use the date command
>in ticks at the time you set the filename instead of setting it as a
>variable-- I just think it is more readable in the code. I believe I got
>this information from the date man page entry.

>Mike

I prefer using date=`date +"%y%m%d"` so i am able to compare dates
easely.

If you see a "!" in my E-Mail adress, remove it !
S'il y a un "!" dans mon adresse E-Mail enlevez le !

 
 
 

Using system date-time as file name

Post by Dr. Wolfgang Otrebsk » Wed, 11 Feb 1998 04:00:00



> On Fri, 06 Feb 1998 14:05:51 -0600, Michael Roeder


> >> Hi:

> >> Could one of you Unix wizards help me here.  What Unix commands does one
> >> use to use the system date-time as a filename via a shell script?  I am
> >> using AIX.

<snipped lots of useful information>
I had to prepare filenames for archival in a dos based environment.
Simply translated the current system time to a number of base 36 with
digits from 0-9A-Z in a program. Just now using 6 digits only. program
can be used to translate back in case one needs to know...
Good Luck,
wolfgang
--
Standard disclaimer applies (anyone following advice given here does so
at her/his own risk - I speak for myself and not for my employer).
 
 
 

Using system date-time as file name

Post by Mathew A. Hennes » Wed, 11 Feb 1998 04:00:00




Quote:

>date=`date +"%m%d%y"` (or date +"%d%m%y" for all of you not in the US).

        This is not Y2k compliant.  Use (in Korn shell) date=$(date
+%m%d%Y) or date=$(date +%m%d%C%y)..  _especially_ if you use %y%m%d as a
part of a key in logging or backups.

Share and enjoy,

--
"He does fit the profile perfectly. He's intelligent, but an under-achiever;
 alienated from his parents; has few friends.
 Classic case for recruitment by the Soviets."

 
 
 

Using system date-time as file name

Post by Pete Forma » Thu, 12 Feb 1998 04:00:00


        [snip]
    Raymond> I prefer using date=`date +"%y%m%d"` so i am able to
    Raymond> compare dates easely.

Whichever order you use it is a good idea to use some extra quotes.

    date=`date +"%y""%m""%d"`

This avoids a * gotcha if the script is checked into SCCS.  (Well
probably not in this example but it would if the date used hours and
minutes.)
--
Pete Forman
Western Geophysical

 
 
 

Using system date-time as file name

Post by gxp » Fri, 13 Feb 1998 04:00:00


just test



>> Hi:

>> Could one of you Unix wizards help me here. What Unix commands does one
>> use to use the system date-time as a filename via a shell script? I am
>> using AIX.

>> Thanks for any assistance you can provide.

>> Michael Murphy
>> ========

>Assuming you're using Korn shell...

>I set an environment variable called 'date' like this:

>date=`date +"%m%d%y"` (or date +"%d%m%y" for all of you not in the US).

>then, $date has 020698 as its value. You can, of course use the date
command
>in ticks at the time you set the filename instead of setting it as a
>variable-- I just think it is more readable in the code. I believe I got
>this information from the date man page entry.

>Mike

 
 
 

Using system date-time as file name

Post by Stew Redfiel » Sun, 15 Feb 1998 04:00:00


Or check the man page for "date"
Example:
% date +%m.%d.%Y
2.14.1998

My $0.02




>> Well it ain't pretty (the filename that is) but you could just use
command
>> substitution with the date command i.e.

>> $ls
>>    myfile

>> $cat myfile > `date`

>> $ls
>>   myfile
>>   Sat Feb  7 14:20:31 EST 1998

>> You now have a file called "Sat Feb  7 14:20:31 EST 1998". Of course you
>> could use some of the date's formatting options to clean it up a bit.

>Eeeeu -- spaces in a file name are a terrible choice! If you really
>want to use the default date output, substitute the spaces with something
>which you can use later in regular expression matches. eg:

>-->date | sed -e 's/ \{1,\}/-/g'
>Sat-Feb-7-15:03:56-PST-1998

>--
>         _,'|            _.-''``-...___..--';
>        /, \'.      _..-' ,      ,--...--'''

>        `-,;'              ;   ; ; http://www.catmanor.com/moonbeam/
>  __...--''     __...--_..'  .;.'  vi is my shepherd; i shall not font.
> (,__....----'''      (,..--''
>perl -e 'print $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'