LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

zmv

Batch rename files using zsh patterns

TLDR

Rename files lowercase to uppercase
$ zmv '(*)' '${(U)1}'
copy
Add prefix to all files
$ zmv '(*)' 'prefix_$1'
copy
Change file extension
$ zmv '(*).txt' '$1.md'
copy
Rename with sequential numbers
$ zmv -n '*.jpg' 'photo_$((++n)).jpg'
copy
Dry run (show what would happen)
$ zmv -n '(*)' 'new_$1'
copy
Move files to subdirectory
$ zmv '(*.txt)' 'subdir/$1'
copy

SYNOPSIS

zmv [-finqQsvwW] [-C|-L|-M|-p program] [--] srcpat dest

DESCRIPTION

zmv is a Zsh builtin for batch renaming files using pattern matching and replacement. It's more powerful than basic mv for complex renaming operations.The source pattern uses Zsh extended globbing. Parenthesized groups are captured and available as $1, $2, etc. in the destination pattern. Zsh parameter expansion modifiers can transform captured text.Common modifiers: ${(U)1} uppercase, ${(L)1} lowercase, ${(C)1} capitalize, ${1:t} tail (basename), ${1:h} head (directory).zmv must be loaded first: autoload -U zmv

PARAMETERS

-n

Dry run, show what would be done
-f
Force overwrite without prompting
-i
Interactive, prompt before overwriting
-q
Quiet, don't report errors
-Q
Force bare glob qualifiers on pattern
-s
Symbolic link instead of move
-v
Verbose, print each command
-w
Pick out wildcard parts of pattern
-W
Same as -w but with pattern replacement
-C
Copy instead of move
-L
Hard link instead of move
-M
Move (default)
-p program
Use specified program instead of mv

CAVEATS

zmv is Zsh-specific. It won't work in bash or other shells.Always use -n (dry run) first to verify the operation before executing.Patterns use Zsh globbing, which differs from regular expressions. Enable extendedglob (**setopt extendedglob**) for full pattern support.

SEE ALSO

mv(1), rename(1), mmv(1), zsh(1)

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid