Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 11-18-2002, 10:05 AM   #1
Registered: Oct 2002
Posts: 44

Rep: Reputation: 15
Appending current date and time to a file


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
Old 11-18-2002, 10:08 AM   #2
LQ Addict
Registered: Dec 2001
Location: Brooklyn, NY
Distribution: *NIX
Posts: 3,704

Rep: Reputation: 56
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
Old 11-18-2002, 10:41 AM   #3
Registered: Oct 2002
Posts: 44

Original Poster
Rep: Reputation: 15
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.
Old 11-18-2002, 11:52 AM   #4
Registered: Oct 2002
Location: Curitiba - Brazil
Distribution: Conectiva
Posts: 334

Rep: Reputation: 30

# 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
Old 11-18-2002, 01:58 PM   #5
Registered: Oct 2002
Posts: 44

Original Poster
Rep: Reputation: 15
# cat arq > "arq-`date`" doesn't work, cats my 5 meg file!!!

tried mv "filename-'date'.sh"

just renames it to

Thanks though
Old 11-18-2002, 02:09 PM   #6
Registered: Jul 2002
Location: san francisco
Distribution: freebsd
Posts: 102

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

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:

$ 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.

Last edited by leed_25; 11-18-2002 at 02:12 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Get file modification date/time in Bash script cmfarley19 Programming 16 04-15-2015 06:25 PM
Start Date + Time Duration = End Date/Time calculator? ToBe Linux - General 3 09-26-2005 10:17 AM
Question about getting the date/time information from a file shazam75 Linux - General 1 10-31-2004 07:54 AM
Setting environment variable to current date/time nafan Programming 1 08-23-2004 09:04 PM
Where can I look for the config file for modified date and time ForumKid Linux - General 1 09-19-2003 08:05 AM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:50 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration