ntu/README.md

371 lines
13 KiB
Markdown
Raw Normal View History

# NameToUnix
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
**Filename Repair Tool for Linux** · Binary: `ntu`
2025-03-18 05:04:57 +01:00
🔗 Repository: [kitux.de/forgejo/dschlueter/ntu](https://kitux.de/forgejo/dschlueter/ntu)
2025-03-20 01:57:26 +01:00
(german and english)
2025-03-18 05:04:57 +01:00
A powerful command line tool for cleaning up file names according to Linux conventions.
2025-03-20 01:57:26 +01:00
It works under Linux. The program is useful if many file names, e.g. after downloading and unpacking zip files from Windows file systems
2025-03-18 05:04:57 +01:00
contain spaces or special characters. It saves an enormous amount of time by automatically replacing the offending characters.
2025-03-18 03:05:18 +01:00
2025-03-20 03:28:01 +01:00
I have been using a similar program - a Perl script - for about 15 years. It has saved me many, many hours of mindless renaming work. Now I'm learning Rust and wanted to write a useful command line application. ***NameToUnix*** is the result.
2025-03-18 05:28:38 +01:00
2025-03-20 03:32:02 +01:00
This is my first program in Rust. (Please have mercy on me.)
2025-03-18 05:28:38 +01:00
2025-03-18 03:05:18 +01:00
Ein leistungsstarkes Kommandozeilen-Tool zum Bereinigen von Dateinamen gemäß Linux-Konventionen.
2025-03-20 01:57:26 +01:00
Es funktioniert unter Linux. Das Programm ist sinnvoll, wenn viele Dateinamen z. B. nach einem Download und Entpacken von Zip-Dateien aus Windows-Dateisystemen
2025-03-18 04:11:30 +01:00
Leerzeichen oder Sonderzeichen enthalten. Es erspart enorm viel Zeit durch automatisches Ersetzen der störenden Zeichen.
2025-03-18 03:05:18 +01:00
2025-03-20 03:28:01 +01:00
Ich benutze ein ähnliches Programm - ein Perl-Skript - seit ca. 15 Jahren. Es hat mir schon viele, viele Stunden stumpfsinniger Umbenennungs-Arbeit erspart. Nun bin ich dabei, Rust zu lernen und wollte eine sinnvolle Kommandozeilenanwendung schreiben. ***NameToUnix*** ist dabei herausgekommen.
2025-03-18 05:28:38 +01:00
2025-03-20 03:32:02 +01:00
Dies ist mein erstes Programm in Rust. (Bitte seid gnädig.)
2025-03-18 05:28:38 +01:00
(c) 2025 Dieter Schlüter <dschlueter@kitux.de>
2025-03-18 03:05:18 +01:00
## ⚠️ BREAKING CHANGE in v1.0.0
**Recursion is now opt-in**: As of version 1.0.0, `ntu` processes only the
specified paths and their immediate children by default. Use the `-r` or
`--recursive` flag to enable recursive directory traversal.
**Migration**: Add `-r` to your existing commands:
```bash
# Old (v0.x): ntu /path/to/files
# New (v1.x): ntu -r /path/to/files
```
## Sequences
Starting with v1.1.0, `ntu` supports transformation sequences similar to detox. Sequences control how filenames are transformed:
- **default**: Standard transformation (umlauts→ASCII, spaces→underscores, remove special chars)
- **lower**: Like default, but convert to lowercase
- **upper**: Like default, but convert to UPPERCASE
- **minimal**: Only replace spaces, keep UTF-8 characters
- **utf-8**: UTF-8 friendly (keep umlauts, replace spaces, remove special chars)
```bash
# Use specific sequence
ntu -s lower /path/to/files
# List all available sequences
ntu -L
# List sequences with details
ntu -L -v
```
2025-03-18 05:04:57 +01:00
## Functions / Funktionen
- Replaces spaces and special characters in file and directory names with underscores
- Converts German umlauts to their ASCII counterparts (ä → ae, etc.)
- Supports recursive processing of directories
- Provides preview mode without actual changes
- Allows user-defined replacement rules via configuration file
- Supports exclusion patterns for specific file patterns/directory patterns
2025-03-18 03:05:18 +01:00
2025-03-20 01:57:26 +01:00
---
2025-03-18 03:05:18 +01:00
- Ersetzt Leerzeichen und Sonderzeichen in Datei- und Verzeichnisnamen durch Unterstriche
- Konvertiert deutsche Umlaute in ihre ASCII-Pendants (ä → ae, usw.)
- Unterstützt rekursive Verarbeitung von Verzeichnissen
- Bietet Vorschau-Modus ohne tatsächliche Änderungen
- Ermöglicht benutzerdefinierte Ersetzungsregeln über Konfigurationsdatei
- Unterstützt Ausschlussmuster für bestimmte Datei-Muster/Verzeichnis-Muster
## Installation
2025-03-20 04:29:34 +01:00
### Option 1: Pre-built Binary
Pre-built binaries are available from [Forgejo Releases](https://kitux.de/forgejo/dschlueter/ntu/releases).
Download and extract the appropriate binary for your platform, then move it to `/usr/local/bin/`.
### Option 2: Build from Source (Recommended)
Die ausführbare Datei wird unter `target/release/ntu` erstellt. Du solltest sie mit 'sudo cp target/release/ntu /usr/local/bin/' kopieren. Sie ist dann für alle User verfügbar. Denke daran, die Konfiguationsdatei (s. u.) ebenfalls zu kopieren. Sie kann für jeden User individuell angepasst werden, wenn sie im home-Verzeichnis des Users liegt.
2025-03-20 04:29:34 +01:00
The executable file is created under `target/release/ntu`. You should copy it with 'sudo cp target/release/ntu /usr/local/bin/'. It is then available for all users. Remember to copy the configuration file (see below) as well. It can be customized for each user individually if it is located in the user's home directory.
2025-03-20 04:29:34 +01:00
2025-03-18 03:05:18 +01:00
```bash
git clone https://kitux.de/forgejo/dschlueter/ntu.git # Download repository
cd ntu # Change to download directory
2025-03-20 04:06:04 +01:00
cargo build --release # Build binary
sudo cp target/release/ntu /usr/local/bin/ # copy binary to local bin directory
2025-03-20 04:29:34 +01:00
# Globale Einstellungen / Global Settings
2025-03-20 04:06:04 +01:00
sudo mkdir -p /etc/NameToUnix/ # Create global config directory for NameToUnix in /etc
sudo cp .NameToUnix.conf /etc/NameToUnix/config.toml # Copy config file to this global directory
2025-03-20 04:29:34 +01:00
# Lokale Einstellungen / Local settings
mkdir -p ~/.config/NameToUnix/ # Create a personal config directory for NameToUnix
2025-03-20 04:06:04 +01:00
cp .NameToUnix.conf ~/.config/NameToUnix/config.toml # Copy config file to this personal directory
# Shell-Completion (optional)
sudo cp completions/ntu.bash /etc/bash_completion.d/ntu # Bash completion
# Oder für Zsh:
sudo cp completions/_ntu /usr/share/zsh/site-functions/_ntu # Zsh completion
# Oder für Fish:
sudo cp completions/ntu.fish /usr/share/fish/vendor_completions.d/ntu.fish # Fish completion
# Manpage (optional)
sudo cp man/ntu.1 /usr/share/man/man1/ # Install manual page
sudo mandb # Update man database
2025-03-18 03:05:18 +01:00
```
2025-03-18 05:04:57 +01:00
## Usage
```bash
# Basic usage (non-recursive: only immediate children)
ntu /path/to/files
2025-03-18 05:04:57 +01:00
# Recursive processing (process subdirectories)
ntu -r /path/to/files
# Dry-run: only preview the changes without actual renaming
ntu --dry-run -r /path/to/files
ntu -n -r /path/to/files # Short form
# Use specific config file
ntu --conf /path/to/custom.toml /path/to/files
2025-03-18 05:04:57 +01:00
# Process multiple paths
ntu -r /path1 /path2 /path3
2025-03-18 03:05:18 +01:00
2025-03-18 05:04:57 +01:00
# Exclude specific files
ntu -r -e "*.tmp" -e "backup_*" /path/to/files
2025-03-18 05:04:57 +01:00
# Process symlinks and special files (normally skipped)
ntu -r --special /path/to/files
2025-03-18 05:04:57 +01:00
# Increase verbosity
ntu -r -v /path/to/files
2025-03-18 05:04:57 +01:00
# Also rename the root directory
ntu -r --modify-root /path/to/files
2025-03-18 05:04:57 +01:00
# Combine options
ntu --dry-run -r -v --special /path/to/files
# Use lowercase sequence
ntu -r -s lower /path/to/files
# Minimal mode (only spaces, keep UTF-8)
ntu -s minimal /path/to/files
# UTF-8 friendly mode
ntu -s utf-8 /path/to/files
# List available sequences
ntu -L
# List sequences with details
ntu -L -v
2025-03-18 05:04:57 +01:00
```
**Note:** The following directories/files are automatically excluded:
`.git`, `.svn`, `node_modules`, `.cache`, `__pycache__`
2025-03-18 03:05:18 +01:00
## Verwendung
```bash
# Grundlegende Verwendung (nicht-rekursiv: nur direkte Kinder)
ntu /pfad/zu/dateien
2025-03-18 03:05:18 +01:00
# Rekursive Verarbeitung (Unterverzeichnisse verarbeiten)
ntu -r /pfad/zu/dateien
# Dry-run: Nur Vorschau der Änderungen ohne tatsächliche Umbenennung
ntu --dry-run -r /pfad/zu/dateien
ntu -n -r /pfad/zu/dateien # Kurzform
# Spezifische Config-Datei verwenden
ntu --conf /pfad/zu/custom.toml /pfad/zu/dateien
2025-03-18 03:05:18 +01:00
# Mehrere Pfade verarbeiten
ntu -r /pfad1 /pfad2 /pfad3
2025-03-18 03:05:18 +01:00
# Bestimmte Dateien ausschließen
ntu -r -e "*.tmp" -e "backup_*" /pfad/zu/dateien
2025-03-18 03:05:18 +01:00
# Symlinks und Special Files verarbeiten (normalerweise übersprungen)
ntu -r --special /pfad/zu/dateien
2025-03-18 03:05:18 +01:00
# Verbosity erhöhen
ntu -r -v /pfad/zu/dateien
2025-03-18 03:05:18 +01:00
# Auch das Wurzelverzeichnis umbenennen
ntu -r --modify-root /pfad/zu/dateien
# Optionen kombinieren
ntu --dry-run -r -v --special /pfad/zu/dateien
# Kleinbuchstaben-Sequenz verwenden
ntu -r -s lower /pfad/zu/dateien
# Minimal-Modus (nur Leerzeichen, UTF-8 behalten)
ntu -s minimal /pfad/zu/dateien
# UTF-8 freundlicher Modus
ntu -s utf-8 /pfad/zu/dateien
# Verfügbare Sequenzen auflisten
ntu -L
# Sequenzen mit Details auflisten
ntu -L -v
2025-03-18 03:05:18 +01:00
```
**Hinweis:** Die folgenden Verzeichnisse/Dateien werden automatisch ausgeschlossen:
`.git`, `.svn`, `node_modules`, `.cache`, `__pycache__`
2025-03-18 05:04:57 +01:00
## Configuration File / Konfiguration
2025-03-18 03:05:18 +01:00
2025-03-20 04:06:04 +01:00
Erstelle eine Datei `.NameToUnix.conf` im persönlichen Arbeitsverzeichnis z. B. mit folgendem Inhalt
2025-03-18 04:31:39 +01:00
(alternativ `~/.config/NameToUnix/config.toml`):
2025-03-18 03:05:18 +01:00
2025-03-20 04:06:04 +01:00
Create a file `.NameToUnix.conf` in your personal working directory, e.g. with the following content
2025-03-18 05:04:57 +01:00
(alternatively `~/.config/NameToUnix/config.toml`):
2025-03-18 03:05:18 +01:00
```toml
[replacements]
"foo" = "bar"
"old" = "new"
"alt" = "neu"
".." = "."
"_·_" = "_-_"
"Ä" = "Ae"
"Ö" = "Oe"
"Ü" = "Ue"
"ä" = "ae"
"ö" = "oe"
"ü" = "ue"
"ß" = "ss"
```
2025-03-20 01:57:26 +01:00
Dies ist eine Beispielkonfiguration. Du kannst Die Datei nach Belieben anpassen.
2025-03-20 02:00:02 +01:00
The above is an example configuration. You can customize the file as you wish.
2025-03-18 03:05:18 +01:00
2025-03-20 04:10:24 +01:00
Du solltest auch eine zentrale Konfigurationsdatei /etc/NameToUnix/config.toml im globalen Verzeichnis /etc erstellen (Beispiel):
You should also create a central configuration file /etc/NameToUnix/config.toml in the global directory /etc (example):
2025-03-20 04:06:04 +01:00
```toml
# /etc/NameToUnix/config.toml
# --------------------------------------------
# In dieser Datei können beliebige zusätzliche Schlüssel-Werte-Paare unter [replacements] hinterlegt werden,
# die im Dateistammnamen ersetzt werden. Zum Beispiel:
#
# [replacements]
# "foo" = "bar"
# "old" = "neu"
#
# Dadurch werden in den Dateinamen alle "foo" durch "bar" ersetzt, und "old" durch "neu".
# WICHTIG: Die hartcodierten Transformationen sind aber immer vorrangig und lassen sich auch nicht rückgängig machen.
2025-03-20 04:22:07 +01:00
# Die persönlichen Einstellungen überschreiben diese Einstellungen.
# VORSICHT! Zuerst mit 'ntu -n <path>' testen
2025-03-20 04:22:07 +01:00
# --------------------------------------------
# In this file, any additional key-value pairs can be stored under [replacements],
# which are replaced in the file master name. For example:
#
# [replacements]
# “foo” = “bar”
# “old” = “new”
#
# This replaces all “foo” with “bar” and “old” with “new” in the file names.
# IMPORTANT: The hard-coded transformations always have priority and cannot be undone.
# The personal settings overwrite these settings.
# BE CAREFUL! First test with 'ntu -n <path>' (Just display the changes)
2025-03-20 04:06:04 +01:00
[replacements]
".." = "."
"_·_" = "_-_"
".-_" = "_-_"
# "" = "" # bewirkt nichts / Dummy entry
```
2025-03-18 04:26:54 +01:00
### Verwendung von NameToUnix
Um die Verwendung von `ntu` zu verstehen, kannst du die folgende Hilfe ausgeben:
2025-03-18 04:26:54 +01:00
```text
ntu --help
2025-03-18 04:26:54 +01:00
```
Die Ausgabe sieht wie folgt aus:
```text
Ein Tool zum Anpassen von Verzeichnis- und Dateinamen an Linux-Konventionen
Usage: ntu [OPTIONS] [PATHS]...
2025-03-18 04:26:54 +01:00
Arguments:
[PATHS]... Pfade (Dateien und Verzeichnisse) zum rekursiven Anpassen
Options:
-q, --quiet Ausgaben unterdrücken (keine Umbenennungsinfos auf stdout)
-n, --dry-run Nur anzeigen, aber keine realen Änderungen vornehmen (dry-run)
2025-03-18 04:26:54 +01:00
-f, --force Existierende Dateien überschreiben
-e, --exclude <PATTERN> Zu ignorierende Muster (-e "*.py", mehrere können angegeben werden)
-v, --verbose Ausführliche Debug-Informationen
--modify-root Erlaubt, auch das Wurzelverzeichnis anzupassen
--special Auch symbolische Links und Special Files verarbeiten
2025-03-18 04:26:54 +01:00
-h, --help Print help
-V, --version Print version
```
2025-03-18 05:04:57 +01:00
### Usage of NameToUnix
```text
A tool for adapting directories and file names to Linux conventions
Usage: ntu [OPTIONS] [PATHS]...
2025-03-18 05:04:57 +01:00
Arguments:
[PATHS]... Paths (files and directories) for recursive customization
Options:
-q, --quiet Suppress output (no renaming info on stdout)
-n, --dry-run Only display, but do not make any real changes (dry-run)
2025-03-18 05:04:57 +01:00
-f, --force Overwrite existing files
-e, --exclude <PATTERN> Patterns to be ignored (-e "*.py", several can be specified)
2025-03-18 05:04:57 +01:00
-v, --verbose Detailed debug information
--modify-root Allows you to customize the root directory as well
--special Also process symbolic links and special files
2025-03-18 05:04:57 +01:00
-h, --help Print help
-V, --version Print version
```
2025-03-18 03:50:39 +01:00
## Test
2025-03-18 04:05:44 +01:00
Im Verzeichnis [***./test***](./test) gibt es ein bash-Skript [***create_test_tree.sh***](test/create_test_tree.sh), das lokal 21 Test-Verzeichnisse und 400 Dateien mit skurrilen Zufallsnamen erzeugt. Damit kannst Du ***NameToUnix*** ausprobieren:
***ntu -n ./testverzeichnis*** (nur Anzeige der Änderungen)
2025-03-18 04:05:44 +01:00
oder
***ntu ./testverzeichnis*** (Anzeige mit Umbenennen).
2025-03-18 03:50:39 +01:00
2025-03-18 05:04:57 +01:00
In the directory [***./test***](./test) there is a bash script [***create_test_tree.sh***](test/create_test_tree.sh), which locally creates 21 test directories and 400 files with bizarre random names. You can use this to try out ***NameToUnix***:
***ntu -n ./testverzeichnis*** (display changes only)
2025-03-18 05:04:57 +01:00
or
***ntu ./testverzeichnis*** (display with renaming).
2025-03-18 05:04:57 +01:00
## Lizenz / License
This project is licensed under the MIT license - see the [LICENSE](LICENSE) file for details.
2025-03-18 03:05:18 +01:00
Dieses Projekt steht unter der MIT-Lizenz - siehe die [LICENSE](LICENSE)-Datei für Details.
2025-03-18 05:04:57 +01:00
## Mitwirken / Contributions
Contributions are welcome! Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on the pull request process.
2025-03-18 03:05:18 +01:00
Beiträge sind willkommen! Bitte lies [CONTRIBUTING.md](CONTRIBUTING.md) für Details zum Prozess für Pull Requests.