So my filename looks like this :
Building+a+Container+for+Robust+Conversations.pdf
I would like to use mmv to rename it like this :
Building_a_Container_for_Robust_Conversations.pdf
Or like this :
BuildingaContainerforRobustConversations.pdf
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'
Now, 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
?
rename 's/\+/_/g' *
or
rename 's/\+//g' *
+
character in the filename. OP wants to replace all occurrences.
Feb 16, 2021 at 12:31
rename all files with "+" to be with "_"
rename "s/+/_/" *
rename all files with "+" to be without any whitespaces
rename "s/+//" *
mmv -n …
would be a good place to start. Have you looked atman mmv
, particularly the examples section?rename
command could save you some troubles withmmv
.