Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I often find myself needing to type out a timestamp into a text file. Is there a way to quickly insert the current timestamp into a file in Ubuntu?

share|improve this question

You can use the date command.

date >> my_file.txt

Where my_file.txt is the file to put the timestamp into.

Look at the manual page for strftime(3) (man 3 strftime) to see some date formatters you can use. For instance:

date +%l:%M >> my_file.txt

Will output something like 9:37 (Hour:Minute) to the text file.

share|improve this answer

Use this command at your shell prompt (or within your shell script):

  • date >> /var/log/my_log_file.log
share|improve this answer

Install xclip:

sudo apt-get install xclip

And run the following in a command prompt:

date +"%Y-%M-%d %H:%M" | while read line; do echo -n "$line"; done | xclip -i -selection clipboard

Then you can paste the datetime stamp via ctrl+v into whatever program you choose. You can put the command in a shell script and run it from a keyboard shortcut for convenience.

share|improve this answer
Why is this any easier than the solutions we gave? It seems like our solutions are much better, and faster, than this. – Wuffers Mar 10 '11 at 13:24
This is more flexible since you can insert the current time into any position of the file from the clipboard. This way I'm not limited to having to append the time to the end of the file. Your solutions are indeed easier and faster if you are content with the limits of appending via command line as opposed to insertion via keyboard shortcut. Insert was a keyword for me. – David Apr 18 '11 at 2:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .