I'm deleting some files from a folder and I want to log the file creation and deletion date in ISO format. I'm able to get the deletion date in ISO format but not the creation date in ISO format. Below is the command which I'm trying
find /home/xyz/Pictures -maxdepth 1 -name "*.jpeg" -type f -ctime +48 -printf "%P %t $(date -Is)\n" >> log1.log
Output:
download.jpeg Fri Apr 24 19:30:59.0130057090 2020 2020-11-01T16:12:57+05:30
Required Output:
download.jpeg 2020-04-24T11:12:57+05:30 2020-11-01T16:12:57+05:30
As the find
manual page readily reveals, the printf
format code %t
prints time in the locale's default format. You have to use %T
with an additional format code character to get a different format.
Unfortunately, find
doesn't have ISO format out of the box. %T+
comes pretty close, but is not quite there. So you have to piece together multiple %T
codes into the precise format you want.
%TY-%Tm-%TdT%TT
Depending on your requirements, maybe also add %TZ
to get the time zone.