Get the machine's date and time in a shell script

To get the machine's date and time in a shell script, you can use the built-in date command. Here is an example of how to use the date command in a shell script to get the date and time of your machine:

 echo "`date +"%Y%m%d %H:%M:%S"`"

In this example, we used the date command and a format string to get the current date and time. %Y represents the year, %m represents the month, %d represents the date, %H represents the hour, %M represents the minute, and %S represents the second.

Note that in the date command, the string must be enclosed in quotes so that the formatting characters are interpreted correctly.

After running the script, it will output the current date and time, similar to the following:

 

Guess you like

Origin blog.csdn.net/f746262041/article/details/129189309