I'd like to add a functionality to a project I'm working on, in which as soon as an external controller device powers on, it sends a time-request/command to a ttyusb port of an Ubuntu PC, and the Ubuntu PC sends back the system's time and date. Does such a command exists in Ubuntu?

for example something like:

'timeReq' > /dev/ttyUSB0

In which "time" is the command that would echo back the system's time

  • Does this answer your question? How do I connect to TTY/COM (/dev/ttyUSB0)?
    – K7AAY
    Mar 12, 2020 at 17:29
  • @K7AAY Not really, I'm specifically asking about a special command that would echo back the time and date on my Ubuntu system. The answer you have provided is just to interact with the ttyUSBxx port. But thank you Mar 12, 2020 at 17:34
  • You probably think that you can redirect only echo output. That is wrong.
    – Pilot6
    Mar 12, 2020 at 17:48
  • 1
    Does the edit to the question explain better what you're looking for?
    – K7AAY
    Mar 12, 2020 at 18:06
  • 1
    No: Allowing random external devices without login to issue shell commands would be a tremendous security hole. Imagine all the damage a nefarious USB device could cause!
    – user535733
    Mar 12, 2020 at 21:14

1 Answer 1


The command that outputs system time is date.

You can use format parameters to output only the time.

Also you can send its output to USB using > redirection.


date +%R > /dev/ttyUSB0

The user needs to be a mamber of dialout group or have some other permissions to be able to write there.

You can use man date to see for other formatting options.

  • Just to clarify, If I send "date +%R > /dev/ttyUSB0" as a string from my embedded device to the ttyUSB0 port, will Ubuntu recognize that as a shell command and then send the result back to the USB0 port? Mar 12, 2020 at 17:53
  • I don't know what you mean by "sending back to USB port". This command in Ubuntu will send time to USB port. Everything else about some embedded device is uclear.
    – Pilot6
    Mar 12, 2020 at 17:55
  • 1
    What I mean is, if you write that command (date +%R > /dev/ttyUSB0) in your terminal, it will send the time to the USB port correct? but what I intend is to ask for the time from the embedded device. "a time request" to put it on other words Mar 12, 2020 at 18:02
  • Yes, it is correct. You can try yourself and see what this command deoes without redirection.
    – Pilot6
    Mar 12, 2020 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.