I've got file that start with two dots located in different directories. I need to list them all and change their names in bulk and remove the dots completely.
Any suggestions how to do that?
答案 0 :(得分:1)
由于每个文件的sh
调用,效率不高,但这应该有效,并且是安全的:
find path -type f -name '..*' -execdir sh -c 'fn=$1; dots=${fn%%[^.]*}; cleaned=${fn:${#dots}}; mv -nv "$fn" "$cleaned"' -- {} \;
工作原理:
sh
(带有一系列命令),将文件名作为参数传递(sh -c '...' -- {}
)fn
dots
fn
的长度dots
的子字符串
mv