Trying to rename a series of files on a linux server. Finding the files I want is easy:
find . -type f -wholename \*.mbox
Of course, being mbox files, some of them have spaces in the names, so it becomes:
find . -type f -wholename \*.mbox -print0
I'm piping to xargs so that I can rename the files:
find . -type f -wholename \*.mbox -print0 | xargs -0 -I{} echo ${"{}"/.mbox/}
The echo should return something like INBOX, given INBOX.mbox, however, bash complains:
bash: ${"{}"/.mbox/}: bad substitution
How can I fix this? I'd like to try to keep it in a find/xargs solution if possible, so that I'm not adding a lot of looping constructs around it.
Try
find . -type f -wholename \*.mbox | sed 's/\(.*\)\.mbox/mv "\1.mbox" "\1"/' | sh
This is not 100% fool proof should some of the files contain double quote characters, but I assume you can ignore that :)
GNU Parallel http://www.gnu.org/software/parallel/ has {.} that removes the extension:
find . -type f -wholename \*.mbox -print0 | parallel -0 mv {} {.}
If you know the filenames do not contain \n then this will work aswell:
find . -type f -wholename \*.mbox | parallel mv {} {.}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With