how to remove final “dot” from directory name

烈酒焚心 提交于 2019-12-24 13:42:08

问题


A program messed up my directory putting a dot "." on the end of some file and directory names. What is the easiest way to remove them?

I have thought of removing the last character but not all the files/dirs have a dot on the end. Also removing all the dots is a problem, this will make the extension useless.

What I need is a rename to change name.of.the.file.ext. to name.of.the.file.ext and name.of.the.dir. to name.of.the.dir

Thanks!


回答1:


Go over the files with the dot at the end, rename each if possible (i.e. the target file does not exist).

for file in *. ; do
    [[ -e ${file%.} ]] || mv "$file" "${file%.}"
done
echo Not renamed: *.



回答2:


There might be a rename utility on your machine that will let you do

rename 's/\.$//' *.

Check man rename



来源:https://stackoverflow.com/questions/16460511/how-to-remove-final-dot-from-directory-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!