Kasper Jan Mooijman
Kasper Jan Mooijman

Reputation: 186

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.

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

Answers (2)

glenn jackman
glenn jackman

Reputation: 247072

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

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

Check man rename

Upvotes: 1

choroba
choroba

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

Related Questions