0

I remember a script that existed, that went as follows, it allowed you to move the files in a directory by opening all the file paths of all the files in the directory in a text editor -- then you could edit the file paths in a text editor, and upon exiting your text editor it renamed the files.

I can't seem to find this script. Does anyone know what it is called? I believe it was part of a collection of shell scripts.

Foobar
  • 93

1 Answers1

1

vidir allows you to edit filenames in a text editor. To choose an editor set the EDITOR variable. In Debian or Ubuntu vidir is in the moreutils package.

This is what vidir can do (excerpt from man 1 vidir):

When editing a directory, each item in the directory will appear on its own numbered line. These numbers are how vidir keeps track of what items are changed. Delete lines to remove files from the directory, or edit filenames to rename files. You can also switch pairs of numbers to swap filenames.

It says "edit filenames to rename" but the tool can do more. By editing whole pathnames you can move files to other directories, even to directories that don't exist yet (vidir will try to create them).

After editing you need to save the text file and gracefully exit the editor, only then vidir will do its job. vidir will not do anything if you don't modify the file (this includes saving under another name or in another location) or if the editor exits with failure (i.e. with nonzero exit status). Exiting the editor without saving the file or making the editor fail even after saving the file (example) are ways to abort.

If you're afraid there is a pathname with tab or a newline character somewhere and this will break something in vidir then keep calm. As far as I know vidir will refuse to work with such pathname in the first place.

Examples:

  • vidir
    
    works on the content of the current working directory but does not descend into subdirectories.
  • vidir /chosen/directory
    
    works on the content of the chosen directory but does not descend into subdirectories.
  • vidir *.mp3
    
    works on whatever *.mp3 expands to. This may be quirky if there is no match; see the beginning of this answer.
  • find . -type f | vidir -
    
    works on pathnames provided by find which in general is a very powerful tool (see "Theory" in this answer of mine). Note by default find does descend into subdirectories.
  • EDITOR=kate vidir …
    
    works like vidir … and uses kate as the editor.