开发者

Find all .docx files, add suffix with Bash

I wish to find all .d开发者_StackOverflow社区ocx files, and append them a string. This is my current code, which has a little bug

find -name '*.docx -execdir mv {} {}$string \;

Files are renamed, but string is added like this filename.docx_string and not like that filename_string.docx.


This will do the trick and descend into the subdirectories.

find ./ -name "*.docx" -print | while read i; do mv "$i" `echo "$i" | sed -e 's/\.docx/_stringhere\.docx/'`; done

The sed -e portion will perform a regex substitution for .docx.


Bash 4

shopt -s globstar
for file in **/*.docx
do
  echo mv "$file" "${file%.docx}${string}.docx"
done
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜