From d50c3847192acbb3a5be68b67320fd1819fa81fb Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Tue, 20 Aug 2024 20:42:16 -0300 Subject: Initial import --- mvln | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 mvln (limited to 'mvln') diff --git a/mvln b/mvln new file mode 100755 index 0000000..ec4c359 --- /dev/null +++ b/mvln @@ -0,0 +1,23 @@ +#!/bin/bash +# +# Move a file but keep a symlink behind. +# +# See http://www.linuxquestions.org/questions/linux-newbie-8/script-to-move-old-files-create-symbolic-link-728618/ +# http://lifehacker.com/5270634/move-files-without-breaking-stuff +# https://stackoverflow.com/questions/9251818/bash-move-file-directory-and-create-a-link-of-it +# http://serverfault.com/questions/8108/move-a-file-and-leave-a-soft-link-behind + +# Parameters +BASE="$(basename "$1")" +ORIG="$(dirname "$1")" +DEST="$2" + +# Check +if [ ! -e "$ORIG/$BASE" ]; then + echo "File not found: $ORIG/$BASE" + exit 1 +fi + +# Proceed +mkdir -p "$DEST" +mv "$ORIG/$BASE" "$DEST" && ln -s "$DEST/$BASE" "$ORIG/$BASE" -- cgit v1.2.3