So my filename looks like this :
I would like to use mmv to rename it like this :
Or like this :
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
(Assuming you want to perform the same operation on all files in the current directory...)
To replace + with _ :
mmv '*+*' '#1_#2'
To strip + :
mmv '*+*' '#1#2'
mmv only replaces the first matching + for each file. If you are doing this manually from the shell, and only want/need to do this renaming process once, then you can just repeat the command as many times as is necessary. (Pressing the Up/Down Arrow keys is the easiest way to scroll through your command history.) If you are going to do this, then adding the -v (verbose) flag is advisable, as it will let you know what the mmv command did, and when there is no more work to do. For example:
$ mmv -v '*+*' '#1#2' a+b+c.jpg -> ab+c.jpg : done d+e+f.jpg -> de+f.jpg : done g+h+i.jpg -> gh+i.jpg : done $ mmv -v '*+*' '#1#2' ab+c.jpg -> abc.jpg : done de+f.jpg -> def.jpg : done gh+i.jpg -> ghi.jpg : done $ mmv -v '*+*' '#1#2' *+* -> #1#2 : no match. Nothing done.
If you want all occurrences to be replaced in all of the files in a single pass, or want to embed this command into a script of some sort, then a more elaborate solution, or a different command, is needed. Perhaps consider
rename 's/\+/_/g' * or rename 's/\+//g' *