How do i change the timestamp of a file?
-
When you touch a file in linux it creates an empty file, with the current time and date.
$ touch afile $ ls -l afile -rw-r--r-- 1 training training 0 Jun 7 11:21 afile
You can change the time and date of a file after it is created by using various options to the
touch
command.Change the time and date using date string. Use -d for short.
$ touch --date="2018-03-04 18:21:00" afile $ ls -l afile -rw-r--r-- 1 training training 0 Mar 4 2018 afile
Use more plain language time specification.
$ touch -d "next Wed" afile $ ls -l afile -rw-r--r-- 1 training training 0 Jun 12 2019 afile
$ ls -l afile -rw-r--r-- 1 parallels parallels 0 Jun 12 2019 afile
$ touch -d "5 days ago" afile $ ls -l afile -rw-r--r-- 1 parallels parallels 0 Jun 3 06:13 afile
Instead of using the current time when creating a file, use the
-t
option to specify a timestamp.$ touch -t 201905241355 afile $ ls -l afile -rw-r--r-- 1 training training 0 May 24 13:55 afile
© Lightnetics 2024