0

So I am trying to alter the change timestamp on a file using a script I got from here: Setting/changing the ctime or "Change time" attribute on a file

#!/bin/sh
now=$(date)
echo $now
sudo date --set="qui nov 7 21:05:56 WET 2018"
chmod 777 $1
sudo date --set="$now"

This is the output:

qui nov 8 18:19:39 WET 2018
date: invalid date ‘qui nov 7 21:05:56 WET 2018’
date: invalid date ‘qui nov  8 18:19:39 WET 2018’

What is the matter? The output from date is not a valid date? I tried the fix suggested in the comment to the answer I linked, but it also doesn't work.

chilliefiber
  • 571
  • 2
  • 7
  • 18
  • `touch` is a far less invasive way to modify the timestamp of file than changing the system time. – chepner Nov 09 '18 at 16:34

1 Answers1

0

AFAIK The reason why the arguments are different:

$ info date

   Invoking 'date' with no FORMAT argument is equivalent to invoking it
with a default format that depends on the 'LC_TIME' locale category.  

While under Setting the time:

If given an argument that does not start with '+', 'date' sets the
system clock to the date and time specified by that argument (as
described below).  You must have appropriate privileges to set the
system clock.  Note for changes to persist across a reboot, the hardware
clock may need to be updated from the system clock, which might not
happen automatically on your system.

   The argument must consist entirely of digits, which have the
following meaning:

'MM'
     month
'DD'
     day within month
'hh'
     hour
'mm'
     minute
'CC'
     first two digits of year (optional)
'YY'
     last two digits of year (optional)
'ss'
     second (optional)

   Note, the '--date' and '--set' options may not be used with an
argument in the above format.  The '--universal' option may be used with
such an argument to indicate that the specified date and time are
relative to Coordinated Universal Time rather than to the local time
zone.
AndreDurao
  • 5,600
  • 7
  • 41
  • 61