Edit: Better worded question: How do I only use the touch command to set the modification time of a file to the unix epoch?
I know that the unix epoch value can be retrieved using "data %s", but how do I use the touch command (and only that command) to set the modification time to the unix epoch?
Edit2:
So, I found that this runs without any errors:
touch -m -d ”@$(date +%s)” fileexample.txt
Is this a correct way of setting the modification time of a file to the Unix epoch?
Original Question (disregard)…:
Using the Linux manual for the “touch” command, show the command that you would
use to set the modification time of a file to the Unix epoch.
I understand that the Unix epoch is the amount of second (or miliseconds, I forgot) that has passed since the epoch (1970, January, 01)
What does the question mean by saying: setting the time "to the Unix epoch"?
So, Is it basically asking for today's time, or 1970 01 01, or…?
I know the command for this would be:
touch -m -t time file
But what time do I set it to?
Also, am I meant to use the unix epoch format for the time in the command?
Best Answer
-t
doesn't accept epoch time,-d
doesYou need to use
-d
or--date
instead of-t
and you need to put@
before epochtime format is used, as described indate
manpages:Example:
If you want to change modify time only, use
-m
or--time modify
or--time mtime
, without it both modify and access times are changed.Examples: