Can someone give me a command that would:move a file towards a new directoryand leave a symlink in its old location towards its new one
Move a file and replace it by a symlink
shell script;files;mv;ln
mv moves a file, and ln -s creates a symbolic link, so the basic task is accomplished by a script that executes these two commands:#!/bin/shmv -- $1 $2ln -s -- $2 $1There are a few caveats. If the second argument is a directory, then mv would move the file into that directory, but ln -s would create a link to the directory rather than to the moved file.#!/bin/shoriginal=$1 target=$2if [ -d $target ]; then  target=$target/${original##*/}fimv -- $original $targetln -s -- $target $originalAnother caveat is that the first argument to ln -s is the exact text of the symbolic link. It's relative to the location of the target, not to the directory where the command is executed. If the original location is not in the current directory and the target is not expressed by an absolute path, the link will be incorrect. In this case, the path needs to be rewritten. In this case, I'll create an absolute link (a relative link would be preferable, but it's harder to get right). This script assumes that you don't have file names that end in a newline character.#!/bin/shoriginal=$1 target=$2if [ -d $target ]; then  target=$target/${original##*/}fimv -- $original $targetln -s -- $target $originalcase $original in  */*)    case $target in      /*) :;;      *) target=$(cd -- $(dirname -- $target) && pwd)/${target##*/}    esacesacln -s -- $target $originalIf you have multiple files, process them in a loop.#!/bin/shwhile [ $# -gt 1 ]; do  eval target=\${$#}  original=$1  if [ -d $target ]; then    target=$target/${original##*/}  fi  mv -- $original $target  ln -s -- $target $original  case $original in    */*)      case $target in        /*) :;;        *) target=$(cd -- $(dirname -- $target) && pwd)/${target##*/}      esac  esac  ln -s -- $target $original  shiftfi