Move multiple files, with the power of your editor

Related tags

Command-line mmv
Overview

NOTE FOR USERS THAT WANT TO TRY THIS OUT!

The current code on the master branch doesn’t work as documented, as a newer more powerful interface is being developed. For the doucmented interface, you want to build the latest stable tag:

$ git clone <clone url>
$ cd mmv
$ git checkout tags/v1.0.0 -b v1.0.0-master
$ cargo build -r
$ make install

mmv — multi move

mmv is a command-line utility to move multiple files in a more convenient manner than for-loops. The best way to explain this is with an example. Say you had the following files in the current directory:

$ ls
'The Fellowship of the Ring.mp4'  'The Two Towers.mp4'
'The Return of the King.mp4'

You may be excited because you’re about to watch Lord of the Rings, but the filenames have spaces in them which for various reasons is not a very good idea. You’re hacker though, so you execute the following code in your shell:

$ for old in *; do
>         new=`echo "$old" | tr ' ' '-'`
>         mv "$old" "$new"
> done

Cool, that worked. It is quite a lot to write directly into your shell though, and if the shell you’re using has a CLI that isn’t great with multi-line input you may find yourself with a negative experience.

But wait! Now you decided that actually you would like your filenames to all be in lowercase too, because it’s more consistent with the rest of your filesystem. Well cool, now you can use your shells history to navigate to the previous loop, navigate to the call to tr, and edit its parameters to 'A-Z' 'a-z'. But again, if you have a shell that doesn’t take too kindly to this longer form of script editing then you won’t have a great time (and trust me, very few shells offer a nice experience in this regard).

Let’s try to accomplish this same task using mmv:

$ mmv *

After running the above command, an instance of your editor specified by the $EDITOR variable gets launched with a list of all your files. It looks like so:

The Fellowship of the Ring.mp4
The Return of the King.mp4
The Two Towers.mp4

Now like mentioned previously, you are a hacker. This means that you use vim (or if you’re a real hacker, emacs). You’re not that cool though, so you use vim. Well thankfully vim makes renaming these files very easy:

VGu        " Go into visual-line mode, select the whole document, and lowercase
           " everything
:%s/ /-/g  " Swap all spaces for hyphens
ZZ         " Save and quit

…and just like that, we have turned all those pesky spaces into hyphens and lowercased our filenames, and all it took was 15 keypresses (that includes the enter key, and saving the file)!

Safety

Another advantage of mmv is that it’s a lot safer than your typical for-loop, or embarassingly enough even most file renaming tools I find online (lol). What do I mean by “safer”? Well consider that we want to make the following very simple file renamings:

foo → bar
bar → foo

Most tools I’ve come across for renaming files will rename foo to bar, and then oops!, the original bar file no longer exists and we just lost our data! Even if you were to do this manually (imagine a lot more files) you would need to go and move everything to a temporary directory, and move them back, and it’s kind of just a pain to do manually. Luckily mmv handles this for you!

You might also like...
RustGPT is a ChatGPT UI built with Rust + HTMX: the power of Rust coupled with the simplicity of HTMX 💚

RustGPT 🦀✨ RustGPT.Blog.Post.mp4 Welcome to the RustGPT repository! Here, you'll find a web ChatGPT clone entirely crafted using Rust and HTMX, where

 Amp: A text editor for your terminal.
Amp: A text editor for your terminal.

Amp: A text editor for your terminal. Heavily inspired by Vi/Vim. Amp aims to take the core interaction model of Vim, simplify it, and bundle in the e

Ox is a code editor that runs in your terminal
Ox is a code editor that runs in your terminal

Ox editor Ox is a code editor that runs in your terminal. About The Project Ox is a code editor. It was written in Rust using ANSI escape sequences. I

A filesystem driver that allows you to view your Blackboard course contents as if they were normal files and folders on your system!
A filesystem driver that allows you to view your Blackboard course contents as if they were normal files and folders on your system!

BlackboardFS Blackboard: noun A website so bad that it might as well be a network drive. BlackboardFS is a filesystem driver that allows you to view y

Spawn multiple concurrent unix terminals in Discord

Using this bot can be exceedingly dangerous since you're basically granting people direct access to your shell.

🌌⭐cosmo is a wrapper for Git essentially, allowing you to compress multiple commands into one
🌌⭐cosmo is a wrapper for Git essentially, allowing you to compress multiple commands into one

❯ Cosmo Git tooling of the future New feature: Cosmo hooks! Click here for more info! ❯ 👀 Features Config files (with defaults!) Fast Easy to use Fri

TUI input library supporting multiple backends
TUI input library supporting multiple backends

tui-input WARNING: Most of the functionality is only human tested. A TUI input library supporting multiple backends. This crate can be used with tui-r

Nvm - Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions

Node Version Manager Table of Contents Intro About Installing and Updating Install & Update Script Additional Notes Troubleshooting on Linux Troublesh

CLI tool that make it easier to perform multiple lighthouse runs towards a single target and output the result in a plotable format.

Lighthouse Aggregator CLI tool that make it easier to perform multiple lighthouse runs towards a single target and output the result in a "plotable" f

Owner
Thomas Voss
C && Lisp fanboy. Hater of all things object oriented. Lover of all things whose entire functionality fits in the average UNIX manual.
Thomas Voss
Readme generator for Move packages.

Move Readme Readme generator for Move packages. Documentation is currently extremely sparse but will be improved in the near future. Setup Install the

The Moving Company 2 Jul 31, 2022
Periodically download a youtube playlist, extract audio, convert to mp3, move to directory (possibly synced using syncthing).

auto-dl Periodically download a youtube playlist, extract audio, convert to mp3, move to directory (possibly synced using syncthing). drop https://git

Paul Adenot 10 Jan 12, 2023
Wraps cargo to move target directories to a central location [super experimental]

targo Wraps cargo to move target directories to a central location [super experimental] To use, cargo install --git https://github.com/sunshowers/targ

Rain 18 Jan 7, 2023
RnR is a command-line tool to securely rename multiple files and directories that supports regular expressions

RnR is a command-line tool to securely rename multiple files and directories that supports regular expressions. Features Batch rename files and direct

Ismael González Valverde 219 Dec 31, 2022
Sample and plot power consumption, average frequency and cpu die temperatures over time.

sense Sense is a small tool to gather data on cpu temperature, power usage and clock frequency and plot graphs during some load. Dependencies Sense is

Luuk van der Duim 6 Oct 31, 2022
A command line tool to control the power state of Valve Base Stations 2.0.

lighthousectl A command line tool to control the power state of Valve Base Stations 2.0. Usage Scan All Base Stations It scans endlessly. You can stop

KOBA789 11 Aug 9, 2022
Maccha is an extremely extensible and themable power menu for Windows, macOS, and Linux.

Maccha I hate coffee. Maccha is an extremely extensible and themable power menu for Windows, macOS, and Linux. Plugins Plugins are written in Rust (ot

Kyza 9 May 13, 2023
Shaping, Processing, and Transforming Data with the Power of Sulfur with Rust

Sulfur WIP https://www.youtube.com/watch?v=PAAvNmoqDq0 "Shaping, Processing, and Transforming Data with the Power of Sulfur" Welcome to the Sulfur pro

Emre 6 Aug 22, 2023
Make beautiful colored code listings in LaTeX with the power of TreeSitter.

What is this? This is a CLI tool that consumes TreeSitter's output and transforms it into LaTeX code that will produce syntax-colored code listing. If

Tomáš Lebeda 11 Sep 4, 2023
🚀 JavaScript driver for ScyllaDB, harnessing Rust's power through napi-rs for top performance. Pre-release stage. 🧪🔧

?? JavaScript driver for ScyllaDB. Pre-release stage. ???? ⚠️ Disclaimer ⚠️ This repository and the associated npm package are currently in a ?? pre-r

Daniel Boll 16 Oct 21, 2023