Skip to main content

Utility to replace undesirable characters with underscores in Linux file names

Project description

RENAME-CLEAN - Replace Undesirable Characters with Underscores in Linux File Names

PyPi

The rename-clean command line utility replaces undesirable characters with underscores in Linux file names. Undesirable characters are any that are not ASCII alphanumeric (0-9, a-z, A-Z), underscore (_), hyphen (-), or dot (.). Repeated underscores are reduced to a single underscore and also trimmed from the name stem and suffix. A unique name is always created by appending a number on the name stem if necessary.

I use it after downloading an archive of files from the internet such as a torrent to remove spaces, emojis, and other odd characters from the file names.

Example usage follows:

Clean up all file and directory names in the current directory:

$ rename-clean (or rename-clean .)

Clean up all file and directory names in the current directory and recursively under any child directories:

$ rename-clean -r

Clean up all all jpeg file names in current directory:

$ rename-clean *.jpg

Read a list of names to be cleaned up from a file:

$ rename-clean - <list-of-bad-file-names.txt

Clean up all file and directory names, but also allow + and % characters in names. Note you can allow extra characters by default using the -a/--add option as described in the Command Default Options section below:

$ rename-clean -a '+%'

You can run with the -d/--dryrun option to see what would be changed without actually renaming anything.

The latest version and documentation is available at https://github.com/bulletmark/rename-clean.

Command Default Options

You can add default options to a personal configuration file ~/.config/rename-clean-flags.conf. If that file exists then each line of options will be concatenated and automatically prepended to your rename-clean command line arguments. Comments in the file (i.e. starting with a #) are ignored. Type rename-clean -h to see all supported options.

Installation or Upgrade

Python 3.8 or later is required. Note rename-clean is on PyPI so the easiest way to install it is to use uv tool.

$ uv tool install rename-clean

To upgrade:

$ uv tool upgrade rename-clean

To uninstall:

$ uv tool uninstall rename-clean

Alternatively, run it immediately without explicitly installing it by using the uvx command:

Command Line Options

Type rename-clean -h to view the usage summary:

usage: rename-clean [-h] [-r] [-d] [-q] [-i] [-s] [-l] [-c CHARACTER]
                       [-a ADD]
                       [path ...]

Utility to replace undesirable characters with underscores in Linux file
names. Undesirable characters are any that are not ASCII alphanumeric (`0-9`,
`a-z`, `A-Z`), underscore (`_`), hyphen (`-`), or dot (`.`). Repeated
underscores are reduced to a single underscore and also trimmed from the name
stem and suffix. A unique name is always created by appending a number on the
name stem if necessary.

positional arguments:
  path                  one or more file or directory names to rename, or "-"
                        to read names from stdin. Default is all files in
                        current directory if no path given.

options:
  -h, --help            show this help message and exit
  -r, --recurse         recurse through all sub directories
  -d, --dryrun          do not rename, just show what would be done
  -q, --quiet           do not report changes
  -i, --ignore-hidden   ignore hidden files and directories (those starting
                        with ".")
  -s, --recurse-symlinks
                        recurse into symbolic directory links, default is to
                        rename a link but not recurse into it
  -l, --less-aggressive
                        do not replace underscores unless deletions have been
                        done
  -c, --character CHARACTER
                        character to replace undesirable characters with,
                        default = "_"
  -a, --add ADD         additional characters to allow in names, e.g. "+%"
                        (default: only alphanumeric, "_", "-", and ".")

Note you can set default options in $HOME/.config/rename_clean-flags.conf

License

Copyright (C) 2025 Mark Blakeney. This program is distributed under the terms of the GNU General Public License. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License at https://en.wikipedia.org/wiki/GNU_General_Public_License for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rename_clean-1.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rename_clean-1.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file rename_clean-1.0.tar.gz.

File metadata

  • Download URL: rename_clean-1.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.9

File hashes

Hashes for rename_clean-1.0.tar.gz
Algorithm Hash digest
SHA256 e88fe4024e90027653af3885a0d4148f0078487e55e6e21e6d2d9edf26784a96
MD5 9ad8d9087c7b90e4d2fe6106dc701474
BLAKE2b-256 f1f2f6d7be4300919a86b802192750d223206e7ec6f4501d020d03fedc3e0b75

See more details on using hashes here.

File details

Details for the file rename_clean-1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for rename_clean-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c806b1f4a96619923fccf865127d2a2200c3a9ab059bbb0c09bf149d6f2cd980
MD5 49ca2a3f087296330c63f9c073fddfe7
BLAKE2b-256 0cbee66573b963d32f41238a79ac2901dc4a85579f28e2d7f9aed72df34188c7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page