Home > File & Directory Management > mmv

mmv: Move/Copy/Link Multiple Files by Pattern

The mmv command is a tool used to move, copy, link, or rename multiple files based on specific patterns. It supports wildcard pattern matching similar to regular expressions, making it useful for batch processing a large number of files.

Overview

mmv stands for 'mass move' and is a utility specialized in processing multiple files at once. Unlike `mv`, which is primarily used for moving/renaming individual files, mmv uses wildcard patterns like `*.jpeg` to define a set of source files and transforms them into a new pattern to create a set of target files. Notably, while `rename` focuses on renaming, `mmv` offers integrated functionality for copying (`cp`), linking (`ln`), and moving (`mv`).

Key Features

The key features of the mmv command are as follows:

  • Processes multiple files in batch using wildcard patterns.
  • Provides integrated functions for moving (`mv`), copying (`cp`), linking (`ln`), and renaming files.
  • Similar to `rename` but offers more diverse functionality and intuitive usage.
  • Outputs warning messages in case of conflicts to prevent errors.

Differences between mmv and rename

Both mmv and rename are used for batch renaming files, but they differ in their operation.

  • mmv: Uses wildcards (`*`, `?`, `[ ]`) to define patterns and reconstructs captured parts with numbers (#1, #2). Also provides copy/move/link functions.
  • rename: Specializes in renaming using Perl regular expressions (`s/pattern/replacement/`).

Main Options

The mmv command allows detailed control over file processing and options.

1) File Processing Options

2) Pattern Matching

Generated command:

Try combining the commands.

Description:

`mmv` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Examples

Learn the functionality of the mmv command through various usage examples.

Change File Extension

mmv '*.jpeg' '#1.jpg'

Changes all `.jpeg` extensions in the current directory to `.jpg`.

Add Prefix to File Names

mmv '*.txt' 'doc_#1.txt'

Adds the prefix `doc_` to all `.txt` files.

Move to Directory

mmv '*.log' '/var/log/#1.log'

Moves all `.log` files in the current directory to the `/var/log` directory.

Change Case

mmv '*.*' '#l1.#l2'

Changes uppercase characters in filenames to lowercase.

Preview Changes

mmv -n '*.bak' '#1.old'

Checks the result of changing `.bak` extensions to `.old` without actually modifying the files.

Installation

mmv is not included by default in most Linux distributions, so you need to install it using the commands below.

Debian/Ubuntu

sudo apt update
sudo apt install -y mmv

RHEL/CentOS/Fedora

sudo dnf install -y mmv

Arch Linux

sudo pacman -S mmv

Tips & Cautions

Here are some points to keep in mind when using the mmv command.

Tips

  • mmv's pattern syntax is similar to shell wildcards. `*` means any string, and `?` means a single character. An `*` in `from_pattern` can be referenced by numbers like `#1`, `#2` in `to_pattern`.
  • If filenames conflict, `mmv` by default does not perform the operation and outputs a warning. You can use the `-f` option to forcefully overwrite and ignore conflicts, but be careful of data loss.
  • Always enclose pattern strings in single quotes (`'`) to prevent regular expressions and wildcard patterns from being expanded by the shell.

Related commands

These are commands that are functionally similar or are commonly used together.


Same category commands