1

I am looking for a unix command-line program for renaming file (or files) visually, in an editor or inline (in the same manner as you rename a file on your desktop).

Example. I often need to rename a file somewhere deep. Imagine a file with a wrong .js.txt extension (_ is a cursor):

$ mv deep/inside/there/is/a/file.js.txt _

It is confusing to repeat the whole path as second argument to mv:

$ mv deep/inside/there/is/a/file.js.txt deep/inside/there/is/a/file.js

(I know I can use the mouse, but it is still error-prone). I'd better press Home and change mv to a visual renamer (imagine it's called vmv). E.g.:

$ vmv somewhere/deep/inside/there/is/a/file.js.txt
EDIT FILE NAME: somewhere/deep/inside/there/is/a/file.js.txt_
user31494
  • 4,143

1 Answers1

3

Write your own. Put this in a file called vmv, make it executable, put it in ~/bin or wherever you'd like:

#!/bin/bash
for oldname; do
    read -rep "Edit: " -i "$oldname" newname
    if [[ $oldname != $newname ]]; then
        mv -v "$oldname" "$newname" || exit $?
    fi
fi

Does exactly what you want.


In bash, you can edit the current command line in an editor:

mv deep/inside/there/is/a/file.js.txt Ctrl-XCtrl-E

moreutils has:

vidir

Debian comes with a Perl script that accepts regexps:

prename 's/\.txt$//' file.js.txt
grawity
  • 501,077