Use vidir to quickly edit filenames in your editor

If you have installed moreutils (see below), you can type vidir to open up the current working directory in your $EDITOR. You can use all the power of your editor to edit and/or delete filenames and directories. Editing a line will rename the file or directory, deleting a line will remove the file or directory.

The following will list all your JPEG pictures in the current directory in your editor:

$ vidir *.jpeg

vidir is not recursive by default: if you want to recursively edit filenames, you can do:

$ find -type f -name '*.jpeg' | vidir -  # take note of the trailing dash -

Deleting non-empty directories

When trying to delete a non-empty directory, vidir will complain:

/usr/bin/vidir: failed to remove ./non-empty-directory: Directory not empty

We can use find again:

$ ls -1 non-empty-dir
file1.txt
file2.txt
$ find | vidir -
1   ./non-empty-dir
2   ./non-empty-dir/file1.txt
3   ./non-empty-dir/file2.txt

When we delete all the files from the directory and the directory itself, the directory will be deleted.

To see what vidir is actually doing, you can pass it the -v or --verbose flag:

$ find | vidir -v -
removed './non-empty-dir/file2.txt'
removed './non-empty-dir/file1.txt'
removed './non-empty-dir'

How to install

In Arch Linux, you can install the moreutils package with sudo pacman -S moreutils. On Debian distros, you can run sudo apt install moreutils.

Leave a Reply

Your email address will not be published. Required fields are marked *