Name clashes
The first question you need to ask yourself is if there is a chance of name clashes. In other words; if there possibly exist both a hidden version and a non-hidden version of the same directory or file in one and the same directory.
From bottom to top
Assuming that is not the case, this is one of the situations you need to rename from bottom to top, since you cannot rename (move) files inside folders that were just renamed; the script will not find them anymore and break.
Making hidden files visible
Furthermore, while writing this answer, a comment of @Rinzwind just popped up above my head, mentioning pressing Ctrl+H will make all hidden files and folders visible, which is true of course.
If you nevertheless would like to rename the files and folders:
A script to do so
#!/usr/bin/env python3
import os
import sys
import shutil
directory = sys.argv[1]
for root, dirs, files in os.walk(directory, topdown=False):
for f in files:
if f.startswith("."):
shutil.move(os.path.join(root, f), os.path.join(root, f[1:]))
for dr in dirs:
if dr.startswith("."):
shutil.move(os.path.join(root, dr), os.path.join(root, dr[1:]))
How to use
- Copy the script into an empty file, save it as
rename_dotted.py
Open a terminal and type the command:
python3 /path/to/rename_dotted.py '<directory>'
where '<directory>'
is the directory, needs to be in quotes if it includes one or more spaces.
As always, please first try on a sample.