Remove Japanese Text from Multiple Folders on Linux
How to Remove Japanese Text from Multiple Folder Names on Linux
Do you have many folders whose names contain both Japanese and English text? Renaming each folder manually can be slow, especially when the collection includes hundreds of nested directories. On CachyOS and other Linux distributions, you can remove Japanese text from multiple folder names at once with a Python script.
This guide includes a preview mode, conflict protection, and an option to keep or remove Kanji. The script only renames folders—it does not delete them or modify the files stored inside.
Example folder names
Suppose your folders have names like these:
進撃の巨人 Attack on Titan
君の名は Your Name
アニメ Collection
日本 Music
After removing the Japanese text, they will become:
Attack on Titan
Your Name
Collection
Music
The script also removes extra spaces left behind after the Japanese characters are deleted.
Japanese characters covered by the script
Japanese writing commonly uses three character groups:
- Hiragana, such as
あ,の, andは. - Katakana, such as
ア,メ, andカ. - Kanji, such as
日,本, and語.
The script can remove all three groups. It also covers half-width Katakana and common Japanese iteration marks.
Kanji requires special care because the same CJK characters are also used in Chinese. If your folders contain Chinese names that you want to preserve, disable Kanji removal as explained later in this guide.
Requirements
Python is usually installed by default on CachyOS. Confirm that it is available by running:
python --version
If the terminal displays a Python version number, you can continue. Before processing important folders, create a backup or test the script on a small sample directory.
Navigate to the parent folder
Open a terminal and move to the directory containing the folders you want to rename:
cd "/path/to/parent/folder"
For example:
cd "/home/username/Videos/Anime"
Keep the quotation marks when the path contains spaces.
Confirm your current directory with:
pwd
You can also display its contents with:
ls
Preview the Japanese folder name changes
Run the following script first. It only displays the proposed changes and does not rename anything:
python - <<'PY'
import os
import re
REMOVE_KANJI = True
ranges = [
r"\u3040-\u309F", # Hiragana
r"\u30A0-\u30FF", # Katakana
r"\u31F0-\u31FF", # Katakana Phonetic Extensions
r"\uFF65-\uFF9F", # Half-width Katakana
r"\u3005-\u3007", # Common iteration and ideographic marks
]
if REMOVE_KANJI:
ranges.extend([
r"\u3400-\u4DBF", # CJK Unified Ideographs Extension A
r"\u4E00-\u9FFF", # Common CJK Unified Ideographs
r"\uF900-\uFAFF", # CJK Compatibility Ideographs
])
japanese = re.compile("[" + "".join(ranges) + "]+")
for root, dirs, files in os.walk(".", topdown=False):
for name in dirs:
new_name = japanese.sub("", name)
new_name = re.sub(r"\s+", " ", new_name).strip()
if not new_name:
print(f"SKIPPED, name would be empty: {os.path.join(root, name)}")
continue
if new_name == name:
continue
old_path = os.path.join(root, name)
new_path = os.path.join(root, new_name)
if os.path.exists(new_path):
print(f"SKIPPED, name already exists: {old_path} -> {new_path}")
else:
print(f"PREVIEW: {old_path} -> {new_path}")
PY
Review every line marked PREVIEW. No folder names have been changed at this stage.
A SKIPPED message means the script ignored a folder because its new name would be empty or another folder already uses the proposed name.
Remove Japanese text from multiple folder names
After confirming that the preview is correct, run the following version to apply the changes:
python - <<'PY'
import os
import re
REMOVE_KANJI = True
ranges = [
r"\u3040-\u309F", # Hiragana
r"\u30A0-\u30FF", # Katakana
r"\u31F0-\u31FF", # Katakana Phonetic Extensions
r"\uFF65-\uFF9F", # Half-width Katakana
r"\u3005-\u3007", # Common iteration and ideographic marks
]
if REMOVE_KANJI:
ranges.extend([
r"\u3400-\u4DBF", # CJK Unified Ideographs Extension A
r"\u4E00-\u9FFF", # Common CJK Unified Ideographs
r"\uF900-\uFAFF", # CJK Compatibility Ideographs
])
japanese = re.compile("[" + "".join(ranges) + "]+")
for root, dirs, files in os.walk(".", topdown=False):
for name in dirs:
new_name = japanese.sub("", name)
new_name = re.sub(r"\s+", " ", new_name).strip()
if not new_name:
print(f"SKIPPED, name would be empty: {os.path.join(root, name)}")
continue
if new_name == name:
continue
old_path = os.path.join(root, name)
new_path = os.path.join(root, new_name)
if os.path.exists(new_path):
print(f"SKIPPED, name already exists: {old_path} -> {new_path}")
continue
os.rename(old_path, new_path)
print(f"RENAMED: {old_path} -> {new_path}")
PY
The script processes nested folders recursively and starts with the deepest directories. This order prevents path errors when a parent folder also needs to be renamed.
How to keep Kanji in folder names
By default, the script contains:
REMOVE_KANJI = True
This setting removes Hiragana, Katakana, and common Kanji characters. Change it to the following if you only want to remove Hiragana and Katakana:
REMOVE_KANJI = False
For example, with Kanji removal disabled:
日本 アニメ Japan Anime
will become:
日本 Japan Anime
The Kanji 日本 remains, while the Katakana text is removed.
How the script works
The script performs the following operations:
os.walk()finds every folder under the current directory, including nested subfolders.- Unicode ranges identify Hiragana, Katakana, half-width Katakana, and Japanese marks.
- When
REMOVE_KANJIis enabled, the pattern also includes common CJK ideographs. japanese.sub("", name)removes the selected characters from each folder name.- Extra spaces are collapsed, while leading and trailing spaces are removed.
- Empty names and naming conflicts are skipped automatically.
os.rename()applies the new name without changing the folder contents.
Does the script rename files too?
No. The script only processes directories. Video files, images, subtitles, documents, and other files keep their original names.
Renaming files requires a separate loop over the files list. Handling files separately is safer because it allows you to preview and verify those changes independently.
Does this work on other Linux distributions?
Yes. You can use this method on CachyOS, Arch Linux, EndeavourOS, Ubuntu, Debian, Fedora, openSUSE, and other Linux distributions with Python 3 installed.
Will Korean text also be removed?
No. The character ranges in this script do not include Korean Hangul. A folder containing Korean and English text will remain unchanged unless it also contains Japanese characters or Kanji covered by the CJK ranges.
Safety tips for batch-renaming folders
- Always run the preview script before applying changes.
- Use
pwdto confirm that you are in the correct parent directory. - Back up important data before performing a large batch rename.
- Set
REMOVE_KANJI = Falseif Chinese folder names must remain unchanged. - Review naming-conflict messages before handling skipped folders manually.
- Avoid running the script from your home or system directory when only one collection needs to be processed.
Frequently asked questions
Will the folders or their contents be deleted?
No. The script changes directory names only. All files and subfolders remain inside their original directories.
Why were some folders skipped?
A folder is skipped when removing the selected Japanese characters would leave an empty name or when another folder in the same location already has the proposed name.
Why does the script have a separate Kanji option?
Kanji characters belong to the broader CJK ideograph ranges and are not exclusive to Japanese. The option lets you preserve Chinese names while still removing Japanese Hiragana and Katakana.
Does the script remove extra spaces?
Yes. It removes leading and trailing spaces and converts multiple consecutive spaces into one.
Can I automatically undo the changes?
No. This script does not save a rename history. Use the preview step and create a backup before applying it to important folders.
Conclusion
You can remove Japanese text from multiple folder names on CachyOS without renaming every directory manually. The Python script handles nested folders, prevents empty names and conflicts, and lets you choose whether Kanji should be removed.
Always review the preview first. If your collection contains Chinese folder names, consider disabling Kanji removal before applying the final rename.


