mmv

file managementLinux/Unix
The mmv command is one of the most frequently used commands in Linux/Unix-like operating systems. mmv Move/rename multiple files using patterns

Quick Reference

Command Name:

mmv

Category:

file management

Platform:

Linux/Unix

Basic Usage:

mmv [options] [arguments]

Common Use Cases

    Syntax

    mmv [options] from_pattern to_pattern

    Options

    Option Description
    -m Move mode (default)
    -c Copy mode (instead of moving files)
    -l Link mode (create symbolic links instead of moving)
    -s Symlink mode (create symbolic links instead of moving)
    -d Dirmode (act on directories instead of files)
    -h Handle multiple matches (with special syntax)
    -n No execute (show what would be done without making changes)
    -a Ask for confirmation for each action
    -p Protect existing target files (don't overwrite)
    -g Group undo (all operations succeed or all fail)
    -v Verbose (show extra information)
    -r Use regular expressions instead of wildcards

    Examples

    How to Use These Examples

    The examples below show common ways to use the mmv command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    Basic Examples:

    mmv "*.txt" "#1.text"
    Rename all .txt files to have .text extension instead.
    mmv "file?" "document#1"
    Rename file1 to document1, file2 to document2, etc.

    Advanced Examples:

    mmv "*.JPG" "#1.jpg"
    Convert uppercase .JPG extensions to lowercase.
    mmv "file*.txt" "archive/backup_#1.txt" Move all files matching file*.txt to the archive directory with "backup_" prefix. mmv "chapter?.doc" "book/chapter_0#1.doc" Move chapter1.doc to book/chapter_01.doc, adding leading zeros. mmv -n "*.bak" "/tmp/#1" Show what would happen when moving .bak files to /tmp, without actually moving them. mmv -h "img[0-9][0-9][0-9].png" "photos/picture_#1.png" Handle files with special characters in names. mmv "*_FINAL.doc" "#1.doc" Remove the _FINAL suffix from filenames. mmv -d "proj_*/*" "new_proj_#1/#2" Rename directories and their contents. mmv "a*.txt" "b#1.txt" && mmv "b*.txt" "c#1.txt" Perform sequential renames (first a->b, then b->c).

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    The 'mmv' (multiple move) command is a powerful utility for batch renaming or moving multiple files in a single operation. Unlike basic file operations that work on one file at a time, mmv allows complex pattern-based renaming of many files simultaneously, making it an invaluable tool for file organization and bulk file operations. Key features of the mmv command: 1. Pattern-Based Renaming: mmv uses wildcard patterns to match source files and corresponding replacement patterns to determine the new names, allowing for sophisticated batch renaming operations. 2. Placeholder Substitution: The command uses a '#N' notation in the target pattern to represent wildcards from the source pattern, where N is the position of the wildcard in the source pattern. 3. Multiple Operation Modes: Besides moving/renaming (the default), mmv can also copy files (-c), create hard links (-l), or create symbolic links (-s) using the same pattern matching approach. 4. Directory Support: With the -d option, mmv can operate on directories instead of files, allowing for batch directory renaming. 5. Collision Prevention: mmv automatically detects and prevents potential naming collisions that could result in data loss, ensuring safe batch operations. 6. Simulation Mode: The -n option allows previewing what changes would be made without actually performing them, providing a safety check before committing to potentially large-scale file operations. 7. Interactive Confirmation: When using the -a option, mmv asks for confirmation before each operation, giving fine-grained control over batch processes. Common use cases for mmv include: - Standardizing filenames in a directory (e.g., converting to lowercase, replacing spaces with underscores) - Changing file extensions for multiple files (e.g., .txt to .md, .jpeg to .jpg) - Adding prefixes or suffixes to groups of files (e.g., adding dates or sequence numbers) - Organizing files into subdirectories based on filename patterns - Renumbering sequences of files (e.g., changing img1.jpg, img2.jpg to photo01.jpg, photo02.jpg) - Moving related files to new locations while preserving naming relationships - Creating backup copies of multiple files with modified names The power of mmv lies in its ability to perform complex renaming operations that would otherwise require writing custom scripts. By using pattern matching and substitution, it provides a concise syntax for expressing file transformations that could affect hundreds or thousands of files at once. mmv is not always included by default in Linux distributions and might need to be installed separately. On some systems, similar functionality may be available through other commands like 'rename' or through scripting with tools like 'find' and 'sed'.

    Related Commands

    These commands are frequently used alongside mmv or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the mmv command works in different scenarios.

    $ mmv
    View All Commands