A folder of camera clips sorted into one subfolder per day usually grows a convenience link called latest, so a viewer, a backup job or a person at a terminal can open the newest clips without working out the date. The script that keeps it current is one line, run once a day with that day's date filled in:
ln -sf 2026-11-14 latest
I tested that line over three days of folders. On the second day it exited 0 and left latest pointing at day one. On the third day it did the same. Each run created a new link, just not the one it was asked to replace: it put it inside day one's folder, where it points at itself.
Two more things turned up around the same link. A target written from the wrong directory gives a link that points nowhere, and ln does not object. And the backup copy most people would write, cp -r of the link, copied the link and not one clip.
Disclosure: I make an Android camera app. Nothing below uses its code or describes how it stores anything. The folders are empty or hold a few bytes of random data, and every output is pasted from the scripts shown. Versions:
ln (GNU coreutils) 8.32 cp (GNU coreutils) 8.32 strace -- version 5.16 Linux 6.8.0-138-generic Three days with ln -sf
Day one creates the link. Days two and three run the usual update line.
#!/bin/sh # Two days of clip folders and a "latest" link, updated the way most scripts do it. set -e rm -rf clips && mkdir -p clips/2026-11-13 clips/2026-11-14 clips/2026-11-15 cd clips ln -s 2026-11-13 latest # day one: no link yet, works ln -sf 2026-11-14 latest; echo "day two exit=$?" ln -sf 2026-11-15 latest; echo "day three exit=$?" echo "latest -> $(readlink latest)" find . -type l -printf '%p -> %l\n' | sort for l in 2026-11-13/*; do test -e "$l" || echo "$l does not resolve: $(ls "$l/" 2>&1 | sed 's/^ls: //')"; done day two exit=0 day three exit=0 latest -> 2026-11-13 ./2026-11-13/2026-11-14 -> 2026-11-14 ./2026-11-13/2026-11-15 -> 2026-11-15 ./latest -> 2026-11-13 2026-11-13/2026-11-14 does not resolve: cannot access '2026-11-13/2026-11-14/': Too many levels of symbolic links 2026-11-13/2026-11-15 does not resolve: cannot access '2026-11-13/2026-11-15/': Too many levels of symbolic links Both updates exited 0. latest still names 2026-11-13, and the folder for that day now holds two links nobody asked for.
The GNU manual describes why. When the last argument is a symbolic link to a directory, ln has a choice between replacing the link and creating a new link inside the directory it points to. The manual is plain about which one it picks:
"The default is to treat a destination that is a symlink to a directory just like a directory."
So ln -sf 2026-11-14 latest read latest as the folder 2026-11-13 and made 2026-11-13/2026-11-14. The -f did nothing useful, because there was nothing at that name to replace.
The stray links are broken in an odd way. Each holds the relative string 2026-11-14, and the manual says "A relative symbolic link is resolved in relation to the directory that contains the link". The link lives in 2026-11-13/, so 2026-11-14 resolves to 2026-11-13/2026-11-14, which is the link itself. That is why ls reported a loop rather than a missing file.
Nothing in the output of the update line hints at any of this. A script that checks the exit status sees success every day, and a viewer that opens latest keeps showing the first day's clips.
Two flags that replace the link
ln has two options for this: -n (--no-dereference) and -T (--no-target-directory). The same three days, once with each:
#!/bin/sh # The same three days with -n, and with -T. set -e for opt in -sfn -sfT; do rm -rf clips && mkdir -p clips/2026-11-13 clips/2026-11-14 clips/2026-11-15 cd clips ln -s 2026-11-13 latest ln $opt 2026-11-14 latest ln $opt 2026-11-15 latest echo "$opt: latest -> $(readlink latest); links: $(find . -type l | wc -l)" cd .. done -sfn: latest -> 2026-11-15; links: 1 -sfT: latest -> 2026-11-15; links: 1 Both left one link, pointing at the last day. The difference is in how far each goes. -n only stops ln from following a final argument that is a symlink to a directory. -T stops it from treating the final argument as a directory at all, symlink or not. The manual on -n:
"This option is weaker than the --no-target-directory (-T) option, so it has no effect if both options are given."
The case where the difference shows is a real directory sitting where the link should be, for example if someone once ran mkdir latest by hand. -n would then put the new link inside that directory, the same quiet failure as before. -T refuses, because it will not replace a directory with a link. I would rather have the refusal, so I use -sfT in scripts and -sfn at a prompt, where I can see what happened.
The target is stored as typed
The second trap shows up when the update runs from the parent folder instead of from inside clips:
#!/bin/sh # Making the link from one directory up: the target string is stored as typed. set -e rm -rf clips && mkdir -p clips/2026-11-15 touch clips/2026-11-15/clip_0001.mp4 ln -sfn clips/2026-11-15 clips/latest echo "stored: $(readlink clips/latest)" ls clips/latest/ 2>&1 || true test -e clips/latest && echo "resolves" || echo "dangling" ln -sfn 2026-11-15 clips/latest echo "stored: $(readlink clips/latest)" ls clips/latest/ stored: clips/2026-11-15 ls: cannot access 'clips/latest/': No such file or directory dangling stored: 2026-11-15 clip_0001.mp4 ln stored the string clips/2026-11-15, exactly as typed. Read from inside clips/, where the link lives, that names clips/clips/2026-11-15, which does not exist. The manual allows this without comment: "There are no restrictions against creating dangling symbolic links."
The fix is to write the target as it should be read from the link's own folder, here just the date. GNU ln also has -r (--relative), which works out that string for you from the current directory. I did not add -r to the test above, so it is in the list of things I did not check.
Copying the latest folder to a backup drive
The third trap is on the reading side. A one-off copy of the newest clips to another drive is often written against the link, because the link is the easy name to remember:
#!/bin/sh # Copying the "latest" folder to a backup drive, four ways. set -e rm -rf clips backup && mkdir -p clips/2026-11-15 backup head -c 4096 /dev/urandom > clips/2026-11-15/clip_0001.mp4 ln -sfn 2026-11-15 clips/latest for cmd in "cp -r clips/latest backup/r" "cp -r clips/latest/ backup/r_slash" \ "cp -rL clips/latest backup/rL" "cp -a clips/latest backup/a"; do $cmd dst=${cmd##* } if [ -L "$dst" ]; then kind="symlink -> $(readlink "$dst")"; else kind="directory"; fi printf '%-36s %-26s %s\n' "$cmd" "$kind" "$(ls "$dst"/ 2>&1 | tr '\n' ' ')" done cp -r clips/latest backup/r symlink -> 2026-11-15 ls: cannot access 'backup/r/': No such file or directory cp -r clips/latest/ backup/r_slash directory clip_0001.mp4 cp -rL clips/latest backup/rL directory clip_0001.mp4 cp -a clips/latest backup/a symlink -> 2026-11-15 ls: cannot access 'backup/a/': No such file or directory Plain cp -r clips/latest and cp -a clips/latest both copied the link, not the folder. The backup holds a link containing the string 2026-11-15, which on the backup drive points at nothing. Both commands exited 0, since copying a link is a successful copy.
The manual says when cp follows a link it was given:
"When copying from a symbolic link, cp normally follows the link only when not copying recursively or when --link (-l) is used."
Recursive copying is exactly the case where it does not. Two forms did copy the clip: a trailing slash on the source (clips/latest/), which makes the path name the directory and not the link, and -L, which follows every link it meets. -H would follow only links named on the command line; I did not run it.
The same question applies to anything else that walks the folder, such as rsync, tar or a sync client: each has its own rule about links, and a link named latest at the top of the tree is the one most likely to be handed to them directly.
Is the swap atomic?
A viewer reading latest at the moment the link is replaced could, in principle, catch the name missing. The manual for ln says that does not happen with -f:
"Unless the --backup (-b) option is used there is no brief moment when the destination does not exist"
That line is from the current manual. My ln is 8.32, so I traced the system calls it made:
#!/bin/sh # Which system calls ln -sfn makes when it replaces the link. set -e rm -rf clips && mkdir -p clips/2026-11-14 clips/2026-11-15 cd clips ln -s 2026-11-14 latest strace -f -e trace=symlink,symlinkat,unlink,unlinkat,rename,renameat,renameat2 \ ln -sfn 2026-11-15 latest 2>&1 | grep -v '^+++' | sed -E 's/"Cu[A-Za-z0-9]{6}"/"<random name>"/g' symlinkat("2026-11-15", AT_FDCWD, "latest") = -1 EEXIST (File exists) symlinkat("2026-11-15", AT_FDCWD, "<random name>") = 0 renameat(AT_FDCWD, "<random name>", AT_FDCWD, "latest") = 0 It first tried to create latest directly, got EEXIST, made the new link under a random name, then renamed it over latest. A rename replaces the old name in one step, so a reader sees either the old link or the new one. That matches the manual for this build. Older or non-GNU versions of ln may delete and re-create instead; if a reader depends on it, trace your own.
What I would write instead
- Update the link with
ln -sfT:ln -sfT 2026-11-15 clips/latest. The target is the bare folder name even when the command runs from the parent folder, because it is read from where the link lives. Iflatestwas ever turned into a real directory, this fails loudly instead of nesting. - Write the target as seen from the link's folder. For a link inside
clips/, the target is the bare folder name. If the script runs elsewhere,cdintoclipsfirst, or useln -r. - Check the result, not the exit status. After the update, compare
readlink clips/latestwith the date you meant. That catches every failure above, including the ones that exit 0. - Copy through the link with a trailing slash or
-L.cp -r clips/latest/ /mnt/backup/2026-11-15copies the clips. Naming the destination by date also keeps the backup readable when the link is gone. - Clean up after the old habit.
find clips -mindepth 2 -type llists links nested inside day folders; on the folders above, those are only the strays.
Things I did not test
- BSD and macOS
lnandcp. BSDlnhas its own-hand-nflags, and itscpfollows different defaults. Everything here is GNU coreutils 8.32 on Linux. -
ln -randcp -H. Both are described above from the manual only. - Readers. I did not run a viewer or web server against
latestduring the swap. The strace shows a rename; how a particular reader caches a resolved path is a separate question. - Other file systems. The test ran on a local Linux file system. FAT and exFAT, common on SD cards and USB drives, do not store symbolic links at all, so a copy to one of them cannot keep the link either way.
Sources. ln quotes are from the GNU coreutils manual page ln: Make links between files. The cp quote is from cp: Copy files and directories. Outputs are pasted unedited from the scripts above.
If you want an old Android phone recording in the background so there is a folder of daily clips to point a link at, the app I make is Background Camera RemoteStream on Google Play. Nothing above depends on it.
ln -sf exits 0 while nesting its new link under the old day's folder, so replace latest using -sfT, store its target relative to where it lives, and back it up through latest/.

