Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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_
share|improve this question
    
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 '11 at 18:54
3  
mv deep/inside/there/is/a/file.js{.txt,} – Ignacio Vazquez-Abrams Jul 14 '11 at 18:58
    
possible duplicate of Reuse text on a bash command – Nifle Jul 14 '11 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 '11 at 10:38
up vote 3 down vote accepted

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
share|improve this answer
    
+1 for two extra solutions I never even knew about (bash and vidir) – user89061 Jul 14 '11 at 19:45

You must log in to answer this question.

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