Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
show 2 more comments

1 Answer

up vote 4 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) –  OrbWeaver Jul 14 '11 at 19:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.