aboutsummaryrefslogtreecommitdiff
path: root/mvln
blob: b79feab744657705840cdacca004c4a87f7b1136 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
ORIG="$1"
DEST="$2"
BASE="$(basename "$1")"

# Check
if [ ! -e "$1" ]; then
  echo "File not found: $1"
  exit 1
fi

# Proceed
mkdir -p "$DEST"
mv "$ORIG" "$DEST" && ln -s "$DEST/$BASE" "$ORIG"