![la fecha no cambiaría desde la consola](https://rvso.com/image/898932/la%20fecha%20no%20cambiar%C3%ADa%20desde%20la%20consola.png)
Necesito cambiar temporalmente la fecha para depurar un script y ejecuto un problema inesperado:
root@xxx:/# LC_ALL=C date
Wed Jan 31 17:09:02 EET 2018
root@xxx:/# LC_ALL=C date -s "2018-01-10 17:09:30"
Wed Jan 10 17:09:30 EET 2018
root@xxx:/# LC_ALL=C date
Wed Jan 31 17:09:28 EET 2018
nota:Tengo una ru_RU
configuración regional, así que la uso LC_ALL=C
para tu comodidad. Usar los comandos sin LC_ALL
cambiar nada.
Supuse que hacía algo mal con la sintaxis o leía man
incorrectamente, así que usé instrucciones deestehilo y no resolvió nada. Los intentos de configurar hwclock para que coincida con la fecha no dieron resultado:
root@xxx:/# LC_ALL=C hwclock --systohc
root@xxx:/# LC_ALL=C hwclock --show
Wed Jan 31 17:18:17 2018 .451473 seconds
root@xxx:/# man hwclock
root@xxx:/# hwclock --set --date='2011-08-14 16:45:05'
root@xxx:/# LC_ALL=C hwclock --show
Sun Aug 14 16:45:09 2011 .389008 seconds
root@xxx:/# LC_ALL=C date
Wed Jan 31 17:21:07 EET 2018
¿Cómo puedo cambiar la fecha?
Sistema:
root@xxx:/# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.3 LTS"
ACTUALIZACIÓN para @Yaron
kovjr@xxx:~$ LC_ALL=C sudo date 120622432007.55
[sudo] password for kovjr:
Thu Dec 6 22:43:55 EET 2007
kovjr@xxx:~$ LC_ALL=C date
Wed Jan 31 18:19:23 EET 2018
Respuesta1
Como se describeaquí:
Ver hora
Para ver la fecha y hora actuales, el siguiente comando será suficiente
date
Fijar tiempo
Cambiar la hora significa establecer una nueva hora. Para configurar la hora en Ubuntu (o cualquier Linux), simplemente ejecute el siguiente comando
sudo date newdatetimestring
donde
newdatetimestring
tiene que seguir el formatonnddhhmmyyyy.ss
que se describe a continuaciónnn is a two digit month, between 01 to 12 dd is a two digit day, between 01 and 31, with the regular rules for days according to month and year applying hh is two digit hour, using the 24-hour period so it is between 00 and 23 mm is two digit minute, between 00 and 59 yyyy is the year; it can be two digit or four digit: your choice. I prefer to use four digit years whenever I can for better clarity and less confusion ss is two digit seconds. Notice the period ‘.’ before the ss.
Digamos que desea configurar la nueva hora de su computadora para el 6 de diciembre de 2007, 22:43:55, entonces usaría:
sudo date 120622432007.55
Ejemplo:
$ sudo date 120622432007.55
[sudo] password for xyz:
Thu Dec 6 22:43:55 IST 2007
$ date
Thu Dec 6 22:43:56 IST 2007
$