On Sat, February 9, 2008 9:20 am, Roger Searle wrote:
> Hi, I have a script that does a wget on a website, which is working
> well.  Before the wget command I am moving the folder that already exists:
>
> mv $HOME/documents/newsite $HOME/documents/newsite-old
>
> which is fine.  So long as the folder newsite-old doesn't already exist
> because the script had previously been run and the folder exists.  If it
> does, I'd get the following:
>
> mv: cannot move `/home/roger/documents/newsite/' to a subdirectory of
> itself, `/home/roger/documents/newsite-old/newsite'
>
> What I would really like to do is be retaining each of the previous
> copies of the newsite-old folder, and having the script append an
> increasing number to the folder name each time it ran, ie newsite-old1
> then newsite-old2 etc.
>
> How could I modify the mv command so that it did this for me?
>
> Hoping this makes sense,
> Roger
>
>


possibly by either:

a) testing what folders exist and naming the new folder by maximum +1, but
the programming of that doesn't immediately spring to mind, note that if
you use one digit you will soon run out of namespace, start at 00, 01 etc
and you will get at least 100; or

b) adding the date and time of the fetch to the dir name, like:

 mv $HOME/documents/newsite $HOME/documents/newsite-${date +%F}

date +%F returns 2008-02-09 today, so they will naturally sort in date
order. If you are going to od this more than once a day, come up with a
date string that adds the time too (see man date, its very flexible).


-- 
Nick Rout

Reply via email to