[Wylug-discuss] Copy files by date

Smylers Smylers at stripey.com
Thu Jan 26 06:26:25 UTC 2012


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



More information about the Wylug-discuss mailing list