如何删除最终的“点"从目录名称 [英] how to remove final "dot" from directory name

查看:64
本文介绍了如何删除最终的“点"从目录名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个程序弄乱了我的目录,并加了点".在某些文件和目录名称的末尾.删除它们的最简单方法是什么?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆