重命名一系列文件 [英] Renaming a series of files
问题描述
find。 -type f -wholename \ * .mbox
当然,作为mbox文件,其中一些在名称中的空格,所以它变成:
find。 -type f -wholename \ * .mbox -print0
可以重命名这些文件:
find。 -type f -wholename \ * .mbox -print0 | xargs -0 -I {} echo $ {{}/。mbox /}
应该返回类似于INBOX,给INBOX.mbox,但是,bash抱怨:
bash:$ {{}/。 mbox /}:坏取代
我该如何解决这个问题?如果可能的话,我想尽量保留在find / xargs解决方案中,这样我就不会在它周围增加很多循环结构。
试试
find。 -type f -wholename \ * .mbox | sed's / \(。* \)\.mbox / mv\1.mbox\1/'| sh
如果某些文件包含双引号字符,这不是100%你可以忽略:)
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 :)
这篇关于重命名一系列文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!