I've this structure

  • 2011-04-18T07.32.19UTC
  • 2011-04-19T07.32.19UTC
  • 2011-04-20T03.15.01UTC

Every night, a new directory based on the current date is created.
I would create a symbolic link on the latest directory created:

mysimlink --> 2011-04-20T03.15.01UTC

But tomorrow I would see

mysimlink --> 2011-04-21T03.15.01UTC

How can I do it?

  • Without knowing which operating system and how the "2011-04-21T03.15.01UTC" is being created it is difficult to offer solid advice. – Mokubai Apr 20 '11 at 11:34

You need to write a script which will removes the existing symlink and then creates a new symlink pointing at the directory with today's date. Here is some code:

today=$(date +%Y-%m-%d)

# find today's directory
todayDir=$(ls -d $today*)

# if the directory exists
if [ -d $todayDir ]
    rm -f mysymlink
    ln -s $todayDir mysymlink

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.