How to Batch Move, Rename, and Copy Files in Linux Using the mmv Command

Renaming or reorganising dozens of files matching complex patterns in the Linux terminal often leads system administrators to write multi-line Bash loops involving sed, awk, or string parameter expansion. While standard GNU utilities like mv handle single file moves, they cannot parse wildcard transformations across groups of files simultaneously.

The standard Linux command-line utility mmv (Multiple Move) is specifically engineered for safe batch moving, copying, appending, and linking. It uses custom wildcard pattern matching where matched wildcard segments in the source pattern can be referenced by index numbers in the destination pattern.

Installing mmv in Linux Distributions

Because mmv is dedicated to batch transformations, it is available across standard package repositories:

  • Debian / Ubuntu / Linux Mint:
    sudo apt update && sudo apt install mmv
  • Fedora / RHEL:
    sudo dnf install mmv
  • Arch Linux:
    sudo pacman -S mmv

Understanding mmv Wildcard Indexing Syntax

The defining power of mmv lies in its indexed wildcard replacement system. When you define wildcards in the source argument, mmv captures each matched segment into numbered tokens (#1, #2, #3, etc.):

  • * matches any string of zero or more characters.
  • ? matches any single character.
  • [abc] matches any single character enclosed in brackets.
  • #1 inserts the exact text matched by the first wildcard in the source pattern.
  • #2 inserts the text matched by the second wildcard, and so on.

Note: Always enclose both the source pattern and target pattern in single quotes ('...') to prevent your shell from expanding the wildcards before mmv parses them.

Batch Renaming File Extensions

To convert all files with a .jpeg extension to .jpg in the current working directory:

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

In this command, * matches the filename stem, and #1 places that identical stem back into the target filename followed by .jpg.

Swapping Filename Segments and Prefixes

Suppose you have data files named in the format report_2026_q1.csv and you need to rearrange them into q1_2026_report.csv:

mmv 'report_*_*.csv' '#2_#1_report.csv'

Here, the first wildcard (*) matches the year (2026) as #1, while the second wildcard matches the quarter (q1) as #2. The destination pattern swaps their positions effortlessly.

Case Conversions (Uppercase and Lowercase)

The mmv tool supports built-in case conversion specifiers within token replacements:

  • #l1 converts the matched string of token 1 to all lowercase.
  • #u1 converts the matched string of token 1 to all uppercase.

To convert all uppercase .TXT files to lowercase .txt extensions and lowercase filenames:

mmv '*.[Tt][Xx][Tt]' '#l1.txt'

Simulating Changes with Dry-Run Mode (-n)

Before modifying production logs or sensitive datasets, verify your patterns using the dry-run flag -n:

mmv -n '*.htm' '#1.html'

Output:

index.htm -> index.html
about.htm -> about.html
contact.htm -> contact.html

This command outputs the exact planned transformations to standard output without executing any file modifications on disk.

Batch Copying, Appending, and Linking

The mmv package provides companion hard links or alias executables for related batch file operations:

  • mcp (Multiple Copy): Duplicates files based on wildcard patterns:
    mcp '*.conf' '#1.conf.bak'
  • mad (Multiple Append): Appends contents of matching files to target destinations.
  • mln (Multiple Link): Creates hard links for matching patterns.

By leveraging mmv for batch reorganisations, you eliminate the risk of accidental filename collisions and avoid writing complex regex shell scripts.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.