Since your primary aim is to have a combined view of your local and external Music folder, I think a union mount via overlayfs
could be used, especially if the files are not being written to.
The basic command is, in older kernel versions (<3.18):
mount -t overlayfs -o lowerdir=/read/only/directory,upperdir=/writeable/directory overlayfs /mount/point
For example:
$ ls Documents
374620-63301.pdf My Kindle Content scan0005.jpg
BPMN2_0_Poster_EN.pdf scan0003.jpg StrongDC++
$ ls devel
cse ossec ubuntu-14.04-desktop-amd64-ssh.iso
nexus scripts zsh-syntax-highlighting
$ sudo mount -t overlayfs -o lowerdir=$PWD/Documents,upperdir=$PWD/devel overlayfs ~/Documents
$ ls Documents
374620-63301.pdf scan0003.jpg
BPMN2_0_Poster_EN.pdf scan0005.jpg
cse scripts
My Kindle Content StrongDC++
nexus ubuntu-14.04-desktop-amd64-ssh.iso
ossec zsh-syntax-highlighting
One drawback is the need for sudo
, which can perhaps be taken care of using a careful NOPASSWD
rule.
In light of Jason's blog post, the mount command for newer kernels changes to using overlay
as the filesystem, instead of overlayfs
, and using an additional workdir
. The kernel documentation now codifies this:
At mount time, the two directories given as mount options "lowerdir"
and "upperdir" are combined into a merged directory:
mount -t overlay overlay -olowerdir=/lower,upperdir=/upper,\
workdir=/work /merged
The "workdir" needs to be an empty directory on the same filesystem as
upperdir.
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/
Best Answer
When the last argument to
ln
is a directory, the links are made in that directory. The man page says:It doesn't matter whether you're creating a hard or symbolic link.
cp
andmv
behave similarly.