如何删除最终的“点"从目录名称 [英] how to remove final "dot" from directory name
问题描述
一个程序弄乱了我的目录,并加了点".在某些文件和目录名称的末尾.删除它们的最简单方法是什么?
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.
我需要的是重新命名,以将 of.the.file.ext.
更改为 of.the.file.ext
和 name.dir.
到 dir.name.
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
谢谢!
推荐答案
在文件末尾加点,然后尽可能重命名(即目标文件不存在).
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: *.
这篇关于如何删除最终的“点"从目录名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!