#!/bin/bash # moves a directory and then links it back # good for moving directories from one partition to another but without changing any settings SCRIPT_NAME='mvln' USAGE_STRING='usage: '$SCRIPT_NAME' ' # Show usage and exit with status show_usage_and_exit () { echo $USAGE_STRING exit 1 } # ERROR file does not exist no_file () { echo $SCRIPT_NAME': '$1': No such file or directory' exit 2 } # Check syntax if [ $# -ne 2 ]; then show_usage_and_exit fi # Check file existence if [ ! -e "$1" ]; then no_file $1 fi # Get paths source_path=$1 destination_path=$2 # Check that destination ends with a slash [[ $destination_path != */ ]] && destination_path="$destination_path"/ # Move source [[ -d "$destination_path" ]] || mkdir -p "$destination_path" mv "$source_path" "$destination_path" # Get original path original_path=$destination_path$(basename $source_path) # Create symlink in source dir ln -s "$original_path" "${source_path%/}"