Reputation: 186
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!
Upvotes: 1
Views: 3202
Reputation: 247072
There might be a rename
utility on your machine that will let you do
rename 's/\.$//' *.
Check man rename
Upvotes: 1
Reputation: 242103
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: *.
Upvotes: 2