[Wylug-discuss] Copy files by date

Towle, William William.Towle at echostar.com
Wed Jan 25 10:14:57 UTC 2012


> running date with the %F format just gives the date
> without a time, so is interpreted as the start of today. But you still
> need a way of passing yesterday's date to the date command

  If it's available, the '--date' argument will happily calculate relative
times suitably. Since the time of day doesn't matter in the command you
want, it suffices to do:
	$ date --date='yesterday' +%F
	2012-01-24
(where, at time of writing:
	$ date +%F
	2012-01-25
)

W.


> -----Original Message-----
> From: wylug-discuss-bounces at wylug.org.uk [mailto:wylug-discuss-
> bounces at wylug.org.uk] On Behalf Of Smylers
> Sent: 25 January 2012 10:01
> To: wylug-discuss at wylug.org.uk
> Subject: Re: [Wylug-discuss] Copy files by date
> 
> linux at sh2515.plus.com writes:
> 
> > I am having trouble with some macs. I need to copy lots of files in
> > subdirectories - temporarily everyday - without cron from server a
> > server b from work created yesterday.
> 
> Are you copying them to the same destination as the previous days files?
> If so then rsync would do this for you; it automatically skips any files
> which already exist in the destination.
> 
> > find . -iname "*.txt" -mtime -1 | xargs -I % cp -r % ~/test/
> >
> > The find on our macs don't have -daystart argument so I am finding it
> > inaccurate. Anyway to copy files by yesterdays date manually starting
> > script everyday?
> 
> If Macs have the -newerXY option (which FreeBSD seems to), then you can
> easily get files modified since the start of today with:
> 
>   $ find . -iname "*.txt" -newermt $(date +%F) | xargs ...
> 
> -newermt says to compare the modification time of files with the time
> specified, and running date with the %F format just gives the date
> without a time, so is interpreted as the start of today. But you still
> need a way of passing yesterday's date to the date command.
> 
> Smylers
> 
> _______________________________________________
> Wylug-discuss mailing list
> Wylug-discuss at wylug.org.uk
> https://mailman.lug.org.uk/mailman/listinfo/wylug-discuss





More information about the Wylug-discuss mailing list