LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Appending current date and time to a file (https://www.linuxquestions.org/questions/linux-general-1/appending-current-date-and-time-to-a-file-35774/)

frankietomatoes 11-18-2002 10:05 AM

Appending current date and time to a file
 
Hi,

I want to append the current date and time to a file from a script.

How is this magic done.

Checked for environment variables like $TIME or $DATE but no luck.

Thanks in advance

neo77777 11-18-2002 10:08 AM

simple
echo `date`>>filename_to_append_to
won't work?
you might as well peruse man date for detailed format of the date that you can manipulate

frankietomatoes 11-18-2002 10:41 AM

Should have made it clear.

I want to append to the filename not the file itself.

Looked at the man page though.

the idea is I have compiled files that I want named by time.

vladkrack 11-18-2002 11:52 AM

Try

# cat arq > "arq-`date`"

there's also a lot of format's this date exit could assume, to see then check his options (%):

# man date

frankietomatoes 11-18-2002 01:58 PM

# cat arq > "arq-`date`" doesn't work, cats my 5 meg file!!!

tried mv filename.sh "filename-'date'.sh"

just renames it to filename-date.sh.

Thanks though

leed_25 11-18-2002 02:09 PM

Hers's a little alias which I use in the bash shell:

Code:

alias otag="date +-%Y-%m%d-%H%Mh%S"
It comes in handy for creating files with timestamps in their names. Like this, for instance:

Code:

$ script file`otag`
Script started, output file is file-2002-1118-1207h49
$ ./configure
                    [. . .]
$ make && make install
                    [. . .]
$ ^D
Script done, output file is file-2002-1118-1207h49

now all of the configuration and make output is in a timestamped file where it can be analysed.


All times are GMT -5. The time now is 11:01 AM.