[Wylug-discuss] Copy files by date

linux@sh2515.plus.com linux at sh2515.plus.com
Thu Jan 26 08:01:54 UTC 2012


The date -v will not work because the version of date is old.
Thanks all for helping though, will stick with original for now or maybe alter for use on today at end of work day like Smylers example.

Just to clarify xargs -I % I found on the web. I was using find -exec then looked on man page and saw xargs so looked at that, but couldn't workout how to cp with xargs. My normal use of copy is 
cp source destination
so couldn't think of how cp would work with xargs, so I can't take credit for xargs -I %. However if I understand correctly, please clarify if not, you can use anything? Eg 
xargs -I Fred cp Fred /destination/folder 
But % also helps with keeping format correct?

On my mobile so excuse the format of e-mail.

Regards

Scott

----- Reply message -----
From: "Smylers" <Smylers at stripey.com>
Date: Thu, Jan 26, 2012 06:26
Subject: [Wylug-discuss] Copy files by date
To: <wylug-discuss at wylug.org.uk>

linux at sh2515.plus.com writes:

> > > 2nd how would I use this code against a file date?
> >
> > Exactly as the command I gave earlier which finds files newer than
> > the start of today, but substituting Aaron's date command from above
> > which gives yesterday's date instead.
> 
> So the date would be put in as a command through -newermt

Yes.

> My knowledge of bash scripting is quite limited

Well you knew about the -daystart option to find, which I hadn't
encountered before, and xargs -I %, which is fairly advanced, so you
obviously do know quite a bit!

Anyway, the construct $(...) in the middle of a command means to run the
command inside the brackets and then use its output as an argument to
the outer command.

> so, would the following script be correct?
> 
> find . -iname "*.txt" -newermt $(date -v -1d +'%F') | xargs -I % cp -r %
> ~/test/

Looks like it to me. I'd first run it with echo before the cp, so you
can see what it would do and sanity check it.

Smylers
-- 
http://twitter.com/Smylers2

_______________________________________________
Wylug-discuss mailing list
Wylug-discuss at wylug.org.uk
https://mailman.lug.org.uk/mailman/listinfo/wylug-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.lug.org.uk/pipermail/wylug-discuss/attachments/20120126/d7e730f3/attachment.htm>


More information about the Wylug-discuss mailing list