ntu/README.md

308 lines
12 KiB
Markdown
Raw Normal View History

# NameToUnix
[![CI](https://github.com/jamulix/NameToUnix/workflows/CI/badge.svg)](https://github.com/jamulix/NameToUnix/actions)
[![Release](https://github.com/jamulix/NameToUnix/workflows/Release/badge.svg)](https://github.com/jamulix/NameToUnix/releases)
[![Version](https://img.shields.io/github/v/release/jamulix/NameToUnix)](https://github.com/jamulix/NameToUnix/releases)
[![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
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
2025-03-18 03:05:18 +01:00
(c) 2025 Dieter Schlüter <dieter.schlueter@linix.de>
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 (Recommended)
Download the latest release for your platform from [GitHub Releases](https://github.com/jamulix/NameToUnix/releases):
```bash
# Linux x86_64
wget https://github.com/jamulix/NameToUnix/releases/latest/download/ntu-linux-x86_64.tar.gz
tar xzf ntu-linux-x86_64.tar.gz
sudo mv ntu /usr/local/bin/
# macOS Intel
wget https://github.com/jamulix/NameToUnix/releases/latest/download/ntu-macos-x86_64.tar.gz
tar xzf ntu-macos-x86_64.tar.gz
sudo mv ntu /usr/local/bin/
# macOS Apple Silicon (M1/M2)
wget https://github.com/jamulix/NameToUnix/releases/latest/download/ntu-macos-arm64.tar.gz
tar xzf ntu-macos-arm64.tar.gz
sudo mv ntu /usr/local/bin/
```
### Option 2: Build from Source
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
2025-03-20 04:06:04 +01:00
git clone https://github.com/jamulix/NameToUnix.git # Download repository
cd NameToUnix # Change to download directory
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
# Bash-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
2025-03-18 03:05:18 +01:00
```
2025-03-18 05:04:57 +01:00
## Usage
```bash
# Basic usage
ntu /path/to/files
2025-03-18 05:04:57 +01:00
# Dry-run: only preview the changes without actual renaming
ntu --dry-run /path/to/files
ntu -n /path/to/files # Short form
2025-03-18 05:04:57 +01:00
# Process multiple paths
ntu /path1 /path2 /path3
2025-03-18 03:05:18 +01:00
2025-03-18 05:04:57 +01:00
# Exclude specific files
ntu -e "*.tmp" -e "backup_*" /path/to/files
2025-03-18 05:04:57 +01:00
# Process symlinks and special files (normally skipped)
ntu --special /path/to/files
2025-03-18 05:04:57 +01:00
# Increase verbosity
ntu -v /path/to/files
2025-03-18 05:04:57 +01:00
# Also rename the root directory
ntu --modify-root /path/to/files
2025-03-18 05:04:57 +01:00
# Combine options
ntu --dry-run -v --special /path/to/files
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
ntu /pfad/zu/dateien
2025-03-18 03:05:18 +01:00
# Dry-run: Nur Vorschau der Änderungen ohne tatsächliche Umbenennung
ntu --dry-run /pfad/zu/dateien
ntu -n /pfad/zu/dateien # Kurzform
2025-03-18 03:05:18 +01:00
# Mehrere Pfade verarbeiten
ntu /pfad1 /pfad2 /pfad3
2025-03-18 03:05:18 +01:00
# Bestimmte Dateien ausschließen
ntu -e "*.tmp" -e "backup_*" /pfad/zu/dateien
2025-03-18 03:05:18 +01:00
# Symlinks und Special Files verarbeiten (normalerweise übersprungen)
ntu --special /pfad/zu/dateien
2025-03-18 03:05:18 +01:00
# Verbosity erhöhen
ntu -v /pfad/zu/dateien
2025-03-18 03:05:18 +01:00
# Auch das Wurzelverzeichnis umbenennen
ntu --modify-root /pfad/zu/dateien
# Optionen kombinieren
ntu --dry-run -v --special /pfad/zu/dateien
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.