LinuxCommandLibrary

qmv

Batch rename multiple files using a text editor

TLDR

Move a single file (open an editor with the source filename on the left and the target filename on the right)

$ qmv [source_file]
copy

Move multiple JPEG files
$ qmv [*.jpg]
copy

Move multiple directories
$ qmv [[-d|--directory]] [path/to/directory1 path/to/directory2 path/to/directory3 ...]
copy

Move all files and directories inside a directory
$ qmv [[-R|--recursive]] [path/to/directory]
copy

Move files, but swap the positions of the source and the target filenames in the editor
$ qmv [[-o|--option]] swap [*.jpg]
copy

Rename all files and folders in the current directory, but show only target filenames in the editor (you can think of it as a kind of simple mode)
$ qmv [[-f|--format]] do .
copy

SYNOPSIS

qmv [options] [files...]

PARAMETERS

-e editor
    Specify the text editor to use instead of the one defined by the $EDITOR environment variable.

-f
    Force operations: overwrite existing destination files without prompting.

-i
    Prompt for confirmation before performing each rename or move operation.

-d
    Perform a dry run: show what changes would be made without actually executing them.

-v
    Enable verbose output: print each rename/move operation as it is performed.

--help
    Display a help message and exit.

--version
    Display version information and exit.

DESCRIPTION

The qmv command, part of the moreutils package, provides an intuitive way to rename or move multiple files interactively. Unlike traditional methods that require scripting or complex regular expressions, qmv generates a temporary file containing a two-column list: original filenames on the left, and corresponding target filenames on the right.

Users then edit this temporary file using their preferred text editor (specified by the $EDITOR environment variable). After saving and exiting the editor, qmv reads the modified list and performs the necessary `mv` operations, ensuring that files are moved or renamed as specified. This interactive approach is particularly useful for complex renaming tasks such as correcting capitalization, adding prefixes/suffixes, reordering file name components, or swapping names between multiple files. It also offers safeguards like dry-run mode and confirmation prompts to prevent unintended changes.

CAVEATS

1. Requires an external text editor: The $EDITOR environment variable must be set, or the -e option must be used to specify an editor.
2. Careful editing: Errors in the temporary file (e.g., invalid characters, non-existent paths, or incorrect formatting) can lead to failed operations or unintended results.
3. Overwriting files: If a target filename already exists, qmv will prompt for confirmation unless the -f (force) option is used, in which case it will overwrite without warning.
4. Filesystem boundaries: Moving files across different filesystems might involve copying and then deleting, which can be slower than simple renames within the same filesystem.

ENVIRONMENT VARIABLE: $EDITOR

qmv relies heavily on the $EDITOR environment variable to determine which text editor to launch. If this variable is not set, qmv will typically fall back to a default editor like vi or nano, or prompt the user, or exit with an error. Setting $EDITOR (e.g., export EDITOR=nano) ensures a consistent editing experience.

INTERACTIVE EDITING FORMAT

When qmv launches the editor, it presents a file with two tab-separated columns. The left column lists the original filenames, and the right column is where you specify the new filenames. Any changes made to the right column will be applied. It is crucial to maintain the tab-separated format and ensure that no newlines are inadvertently introduced within a filename entry. Lines starting with # are treated as comments and ignored.

HISTORY

qmv is part of the moreutils collection of utilities, created by Joey Hess. The moreutils package began development in the early 2000s, aiming to provide a set of small, simple, and powerful tools that extend the functionality of standard Unix commands. qmv stands out for its unique approach to bulk renaming, leveraging the user's familiarity with text editors to solve complex renaming tasks that are cumbersome with simple scripting or regex-based tools. Its design emphasizes interactivity and user control, filling a niche between the basic `mv` command and more advanced, programmatic renaming utilities.

SEE ALSO

mv(1), rename(1), mmv(1)

Copied to clipboard