2015-08-07 11:09:52 +0200, Andreas Schwab: > Andreas Schwab <schwab-td1emuhucqxl1znqvxd...@public.gmane.org> writes: > > Peng Yu > > <pengyu.ut-re5jqeeqqe8avxtiumwx3w-xmd5yjdbdmrexy1tmh2...@public.gmane.org> > > writes: > > > >> Hi, `touch -r` allows one to set the time of a file same as a > >> reference file. What if one wants to set the time to be the last time > >> of multiple files? Is there an easy way to do so? > > > > $ touch -d @$(stat -c %s $files | sort -n | tail -n1) $file > %Y > [...]
Note that that truncates the date to its integer part. You may want to make it %.Y instead. touch -d "@$(stat -c %.Y -- "${files[@]}" | sort -rg | head -n1)" -- "$file" (also, don't foget the quotes around expansions). -- Stephane