Crates.io | bmv |
lib.rs | bmv |
version | 0.1.1 |
source | src |
created_at | 2022-03-22 23:09:46.379467 |
updated_at | 2022-04-10 08:51:47.982112 |
description | Batch Move -- rename large numbers of files easily |
homepage | |
repository | https://github.com/ranmaru22/bmv |
max_upload_size | |
id | 554930 |
size | 55,402 |
Rename large numbers of files easily.
bmv is a Regex-based move/rename tool that can handle many files and directories at once.
bmv commands are formend in a from-to pattern, similar to sed
but in a simpler
way. For example, sed -i 's/foo/bar/' <files>
would be bmv 'foo' 'bar' <files>
in bmv. The replacement is then done across all matches.
bmv '(.*)\.foo' '$1.bar' ./**/*
You can use parentheses to capture any regular expression match in the first
argument and then refer to it using $n
, where n
is a number from 1 to to the
total amount of groups you have, in the second.
You can also use named capture groups, if you prefer, using the ?P<name>
syntax. The example above would then look like this:
bmv '(?P<filename>.*)\.foo' '$filename.bar' ./**/*
If you want to use a literal dollar sign in the second argument, use $$
.
Yes, this is because Rust's regex crate does not support them and bmv uses it for its matching. Like the crate's docs say, "[i]n exchange, all searches execute in linear time with respect to the size of the regular expression and search text."
bmv by itself does not handle resolving the glob, it just receives a list of
files it's supposed to operate on from standard input. So in order to include
hidden files, you need to make sure the shell you're using includes them into
your glob. In zsh
this can easily be done by using the (D)
modifier.
bmv 'foo' 'bar' ./**/*(D)
In bash
you can set dotglob
.
You need to have Rust and Cargo installed.
git clone https://github.com/ranmaru22/bmv.git
cd bmv
cargo install --locked --path=.
This will install the master
branch which has the latest stable release. If
you want the development version, switch to branch develop
.
git checkout develop
You need to have Rust and Cargo installed.
cargo install bmv --locked
tbd
bmv is provided as-is and with no warranty. I developed it for mostly personal use, so it likely has some gotchas and bugs. Feel free to hack it (and if you like, send back a PR, I will happily include any improvements) but use it at your onw risk.