[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: What is the best way to touch a file and set its time of the last ti
From: |
Stephane Chazelas |
Subject: |
Re: What is the best way to touch a file and set its time of the last time of a bunch of other files? |
Date: |
Mon, 31 Aug 2015 16:06:54 +0100 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
2015-08-07 11:09:52 +0200, Andreas Schwab:
> Andreas Schwab <address@hidden> writes:
> > Peng Yu <address@hidden> 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