E
E
EvgMul2018-10-18 19:04:41
linux
EvgMul, 2018-10-18 19:04:41

How to log commands in linux?

Hello. I am interested in such a question. Can I somehow log the execution of a specific command in linux?
Those. I want the result of the command to be php -vsaved to a file, for example. I can do this: php -v > file.logbut I need to save not only the result of the execution, but also the date and time.
Can you please tell me how to implement this?
Thanks in advance to all who respond.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Bogachev, 2018-10-18
@EvgMul

but I need to save not only the result of the execution, but also the date and time

You can, for example, like this:
On repeated executions, a log will be generated like this:
Thu Oct 18 20:13:31 MSK 2018 v10.11.0
Thu Oct 18 20:13:32 MSK 2018 v10.11.0
Thu Oct 18 20:13:33 MSK 2018 v10.11.0

You can format it to your liking - google about echo. For convenience, you can make alias, if you have not come across - you can read about how to use them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question