Batch renaming dozens or hundreds of files matching irregular naming conventions often poses a dilemma in the Linux terminal. Graphical batch renamers lack command-line speed, while CLI tools like rename or parameter expansion loops require constructing flawless regular expressions on the first attempt without visual confirmation.
The standard Linux command-line utility vidir, part of the widely used moreutils package, provides an intuitive alternative. It displays a directory’s contents as an editable text document inside your preferred terminal editor (such as Vim, Neovim, or Nano). By editing filenames with familiar text editor commands, search-and-replace, and multi-cursor features, you can rename, renumber, and delete files simultaneously upon saving.
Installing vidir on Linux
The vidir command is packaged within moreutils across all major Linux distributions:
- Debian / Ubuntu / Linux Mint:
sudo apt update && sudo apt install moreutils - Fedora / RHEL / Rocky Linux:
sudo dnf install moreutils - Arch Linux:
sudo pacman -S moreutils
Configuring Your Preferred Editor
The vidir utility respects your shell’s EDITOR environment variable. If you prefer editing with Nano rather than the system default Vi:
export EDITOR=nano
To persist this preference permanently, add the export line to your ~/.bashrc or ~/.zshrc file.
Launching vidir to Inspect and Edit Directory Contents
To edit all files in your current working directory, run:
vidir
To edit only specific files matching a wildcard pattern:
vidir *.png
When the editor opens, vidir displays each file on a separate line prefixed with an integer index and a tab delimiter:
1 screenshot_2026_01.png
2 screenshot_2026_02.png
3 screenshot_2026_03.png
4 notes_draft.txt
Batch Renaming with Global Find and Replace
The number on the left represents the file’s internal descriptor and must remain untouched. To rename files, simply modify the text string to the right of the tab character:
- Using Vim Search-and-Replace: Press
:and enter:
This changes all instances of:%s/screenshot_/capture_/gscreenshot_tocapture_instantly. - Renumbering Files: Edit the numbers or suffixes manually or using Vim block selection (
Ctrl + V).
Save and exit your editor (in Vim, type :wq; in Nano, press Ctrl + O followed by Ctrl + X). The vidir utility parses your changes and performs all file moves atomically.
Deleting Files via vidir
To delete a file from the filesystem using vidir, simply delete its entire line (both the number and the filename) inside the editor. When you save and exit, vidir prompts for confirmation before permanently removing the deleted items.
Aborting Operations Safely
If you make a formatting mistake or decide not to proceed with the planned renames, quit your editor without saving (in Vim, type :q!; in Nano, press Ctrl + X and choose No). The vidir process terminates cleanly, leaving every file on disk unchanged.
Utilising vidir transforms complex directory restructuring tasks into effortless text editing sessions, providing absolute visual control over batch filesystem transformations.