Can I setup a symlink to the most recent folder?

This isn't possible to do automatically -- Unix provides no facility for symlinks to dynamically change. However, you can have a program in the background that updates the symlink using inotify and the fact that later files sort as being later with LC_COLLATE=C:

#!/bin/bash -e

export LC_COLLATE=C
shopt -s nullglob

base=/path

while inotifywait -e create \
                  -e moved_to \
                  -e moved_from \
                  -e close_write "$base" > /dev/null; do
    dirs=("$base"/dryrun-[0-9]*/)
    (( ${#dirs[@]} )) && ln -sfn -- "${dirs[-1]}" "$base"/latest
done

And here is the result of it running:

% mkdir dryrun-20200320_140935-138yuidx
% ls -l latest
lrwxrwxrwx 1 cdown cdown 39 Mar 20 16:40 latest -> /path/dryrun-20200320_140935-138yuidx/
% mkdir dryrun-20200320_141044-35pfvec6
% ls -l latest                         
lrwxrwxrwx 1 cdown cdown 39 Mar 20 16:40 latest -> /path/dryrun-20200320_141044-35pfvec6/

No. not a symlink, but it is possible by mounting a fuse file-system. I don't know of any fuse file-system that does this. But it is possible to create one.

Tags:

Symlink