Search code examples
bashbatch-rename

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!


Solution

  • 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: *.