Thursday, 3 October 2013

How to copy only the newest sub directory to a destination linux shell script

How to copy only the newest sub directory to a destination linux shell script

I have a parent folder where every day a new subdirectory is automatically
created. The subdirectory naming format is '2013-10-02T1430+0000'. Later
on today the new subdirectory created will be named
''2013-10-03T1430+0000'.
I need a script which will on a schedule automatically copy only the
contents of the latest subdirectory created to another folder.
I have the cp command down ok but I need to somehow subsitute in the cp
source the latest subdirectory name. After doing some research I found the
following command will return the latest or newest subdirectory. ls -tr
ParentFolder | tail -1. How do I get the result of this command to be
placed into the cp command? Is there an easier way of doing this?
Many thanks to all in advance.

No comments:

Post a Comment