3

I was using windows 7,8.1, and 10 previously and there was an option in the Notepad that if I type .LOG at the beginning of the file (which is done only once), every time I open the notepad the date and current time will be automatically added.

Basically, I keep track of all my expenses and it's very important for me to just open the text file and it automatically adds the date and time for me. How can I do this in Ubuntu 15.04?

2
  • Will you be using gedit? Aug 15, 2015 at 17:56
  • yes i will use gedit
    – jud
    Aug 16, 2015 at 8:36

1 Answer 1

4

Simple.

#!/bin/bash
filetoedit="$1"
if [ "$(head -n 1 $filetoedit)" = ".LOG" ] ; then
    date >>$filetoedit
fi
vim "$filetoedit"

Put the above script in a file in your $PATH, make it executable and call your editor through it i.e. if you save it as open.sh, then open any file e.g. foo.txt for editing as :

open.sh foo.txt  

You can adjust the date format (see man date), and change the editor used by replacing vim with your choice.

See "Where should I put my script so that I can run it by a direct command?"

You must log in to answer this question.

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