Re: What is the best way to touch a file and set its time of the last time of a bunch of other files?
2015-08-07 02:21:07 -0500, Peng Yu: > 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? [...] With zsh, touch -r /path/to/*(om[1]) file Would set file's time to that of the newest non-hidden file in /path/to. -- Stephane
Re: What is the best way to touch a file and set its time of the last time of a bunch of other files?
2015-08-07 11:09:52 +0200, Andreas Schwab: > Andreas Schwabwrites: > > Peng Yu > > > > 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
Re: What is the best way to touch a file and set its time of the last time of a bunch of other files?
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 Andreas. -- Andreas Schwab, sch...@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 And now for something completely different.
Re: What is the best way to touch a file and set its time of the last time of a bunch of other files?
Peng Yu pengyu.ut-re5jqeeqqe8avxtiumw...@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 Andreas. -- Andreas Schwab, sch...@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 And now for something completely different.