Do you need to add a shortcut or hotkey to insert or paste timestamp in Linux Mint or Ubuntu?

If so you can follow the next steps in order to add custom shortcut which is inserting the current date and/or time with one click. The output format can be configured as:

  • %Y-%m-%d
  • %Y-%m-%d %H-%M
  • %Y-%m-%d - %H:%M:%S %Z

The steps are tested with Linux Mint 19.3.

Steps to add Hotkey - Insert Timestamp

Step 1: Install xdotool package

The first step install the required package - xdotool - command-line X11 automation tool which is used for date formatting and the output. The package can be installed from the Software Manager or by next command:

sudo apt-get install xdotool

Step 2: Add Custom Shortcut

The step below is described for Linux Mint Cinnamon but I believe that steps are similar for Mate. In order to add a Custom Shortcut for date insert please follow:

  • Main Menu
  • Preferences
  • Keyboard
  • Open tab Shortcuts
  • Navigate to Custom Shortcuts
  • Add custom shortcut - in the bottom left
  • Enter:
    • Name - Insert Date
    • Command - bash -c "sleep .1 && xdotool type \"$(date +'%Y-%m-%d')\""
  • Click to Keyboard bindings - unassigned
  • Select the keyword combination for this shortcut - after pressing the combination you will see a change from unassigned to your combination.

Note: That if the combination is used you will see warning message that you are going to override the combination.

Finally you can test the solution.


Step 3: Customize date format

You can customize the date format by changing the main command:
\"$(date +'%Y-%m-%d')\". Below you can find different formats:

  • Thu 25 Jun 10:45:23 EEST 2020 - bash -c "sleep .5 && xdotool type \"$(date)\""
  • 25/06/20 10:46:21 - bash -c "sleep .5 && xdotool type \"$(date +'%x %X')\""
  • 2020-06-25 - 10:48:16 EEST - bash -c "sleep .5 && xdotool type \"$(date +'%Y-%m-%d - %H:%M:%S %Z')\""
  • 2020-06-25 - bash -c "sleep .5 && xdotool type \"$(date +'%Y-%m-%d')\""
  • 20200625104816 - bash -c "sleep .5 && xdotool type \"$(date +'%Y%m%d%H%M%S')\""

Date format can be customized in many different ways until you get desired output.

Step 4: Additional Options

The option - sleep 0.1 is added in order to prevent truncation of the start of the timestamp. You can increase a bit if this is the case - for example to 0.5 .

type --delay 0 can be added to the command in order to speed up the inserting (which simulate human input):

bash -c "sleep .5 && xdotool type --delay 0 \"$(date)\""

If you like to learn more about adding custom shortcuts in Linux Mint then you can check: