0

Linux noob here! My PC runs Lubuntu 18.04.4 LTS (32-bit). The other day, I learnt about the date command. It's typically not useful for me because I could just look a little above my screen at the taskbar. The date command's format is not soo right as you may know. To get the correct format, I need to type in the weird '%' things which one can find in the digital clock settings. Is there a way in which I can make it the default output of the date command? Maybe change some code in some file. And also tell if the date command is useful to you. I would be keen in knowing that. I guess I could use it for logging the date and time when i copy paste the terminal text.(I often do that to find the mistakes I have done in terminal and even for asking questions in forums.)

1
  • 1
    You could create a shell alias with a date format of your choosing Jul 1, 2020 at 11:04

1 Answer 1

0

Yes, it is true that the date command is less effective compared to taking a look at the desktop gui, but using your desktop might also be less convenient compared to your phone.

However, this command is very useful when you actually have no gui support or any clock prompt, and even more useful when logging scripts and automations.

Here is an example of a simple implementation i like to use when logging stuff:

logev() {
          printf "$(date +%d.%m.%y' '%T'| ') $1\n" >> $logdir
        }

And when I want to log something I use: logev "my_string_or_command_output_here".

All the parameters I added to the date command will result this nice string at the beginning of every line, for example: 01.07.20 16:10:08| "my log string".

There are many many other nice uses for this command, and many of your system commands and programs also use it one way or another.

If you would like to use it for day to day stuff, make an alias of your command with its parameters, as steeldriver suggested at the comment section. Use this expression if you would like a date output same as mine: date +%d.%m.%y' '%T'| ' .

You must log in to answer this question.

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