I often find myself wanting to move a file, then create a symlink where it was.

In doing this by hand I tend to twist my mind. (Esp after doing half a dozen files)

Use cases:

  • Moving all my "dot files" to a folder so i can version control them
  • Moving a file onto a faster disk (scratch) for High Performance Computing

If there is not a single command,
I would appreciate a fish script.
(fish is not a POSIX shell, does not s pport the sh language)

1 Answer 1

function lnmv
    set dest_dir $argv[1]
    set files $argv[2..-1]

    for f in $files
        set dest $dest_dir/$f
        mv -- $f $dest
        and ln -s -- $dest $f
  • Thanks @oxinabox, I was thinking of making that same edit. Mar 17, 2014 at 14:27
  • What do the -- 's do? Mar 18, 2014 at 1:17
  • 2
    In case one of the files begins with the - character, it ensures that the file is handled as a file, not as an option. Mar 18, 2014 at 1:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .