I want to change a file's date to tomorrow 21:00. I used touch, but when I type ls -l
the year of the file is displayed instead of the hour.
-rw-r--r-- 1 ABCD DEF 0 sept. 30 2014 test01
-r-xr-xr-x 1 ABCD DEF 15 sept. 29 09:26 test02
Here for example, we can clearly see "2014" but not "21:00". Strange fact, when I perform touch --date "1 hour ago" test01
it gets displayed correctly, but touch --date "+1 hour" test01
won't work.
Also, editing the file with emacs and saving it will display the hour instead of the year.
Is that normal? How can I change this behaviour without using parameters in ls nor changing the computer's config? (this is for a challenge)
Best Answer
ls
has two time display formats:The intent is to gain horizontal space and not overwhelm the user with information. Showing “from this year” is more obvious than showing the current year and letting the user notice that it is indeed the current year. The exact time of day rarely matters for very old files. Dates in the future are rare.
GNU ls has an option
--full-time
to show the full file time (year, month, day, hour, minute, seconds, nanoseconds, timezone offset) regardless of when that time is. You can tune the output format with the option--time-style
.