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_
7
  • I don't know what remane files in an editor means.. do you mean while open? I don't know if it's possible to rename a file while open in an editor. If you mean writing the copy commands in an editor, how about writing a script, you write your mv lines in there , copy/paste for any repetition of a long directory, and execute it?
    – barlop
    Jul 14, 2011 at 18:54
  • 3
    mv deep/inside/there/is/a/file.js{.txt,} Jul 14, 2011 at 18:58
  • possible duplicate of Reuse text on a bash command
    – Nifle
    Jul 14, 2011 at 19:02
  • 1
  • @Nifle, thanks for pointers! I wasn't looking for bash-specific solution. I use fish as my shell. That's why I didn't mention bash in the question.
    – user31494
    Jul 15, 2011 at 10:38

1 Answer 1

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
1
  • +1 for two extra solutions I never even knew about (bash and vidir)
    – user89061
    Jul 14, 2011 at 19:45

You must log in to answer this question.

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