Last active
October 30, 2025 17:27
-
-
Save ptandler/9c17859b66b1a8fc895181f4af66ef3e to your computer and use it in GitHub Desktop.
Bash script to convert symlinks created by the ntfs-3g driver to the format used by ntfs3.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Converts NTFS-3G IntxLN style symlinks to native symlinks for ntfs3 | |
| # Works recursively on a NTFS partition _that is mounted via ntfs3_! | |
| set -euo pipefail | |
| IFS=$'\n\t' | |
| if [[ $# -ne 1 ]]; then | |
| echo "Usage: sudo $0 /mount/point" | |
| exit 1 | |
| fi | |
| MOUNTPOINT="$1" | |
| if [[ ! -d "$MOUNTPOINT" ]]; then | |
| echo "Error: $MOUNTPOINT not found or not a directory." | |
| exit 1 | |
| fi | |
| LOGFILE="./ntfs-3g-intxln-conversion-$(date +%Y%m%d_%H%M%S).log" | |
| touch "$LOGFILE" | |
| echo "Scanning for IntxLN-encoded NTFS-3G symlinks in $MOUNTPOINT..." | |
| sleep 2 | |
| # Use the 'file' command to detect files starting with "IntxLN" | |
| find "$MOUNTPOINT" -type f | while read -r f; do | |
| head -c 6 "$f" 2>/dev/null | grep -q "IntxLN" || continue | |
| echo "# [FOUND] $f (IntxLN format)" | tee -a "$LOGFILE" | |
| # Extract UCS-2 encoded target path starting from byte 8 | |
| TARGET=$(dd if="$f" bs=1 skip=8 2>/dev/null | iconv -f UTF-16LE -t UTF-8 | tr -d '\000') | |
| if [[ -n "$TARGET" ]]; then | |
| # Backup the old link | |
| echo "mv \"$f\" \"$f-ntfs-3g\"" | tee -a "$LOGFILE" | |
| mv "$f" "$f-ntfs-3g" | |
| # Write a backup script with all symlinks | |
| echo "ln -s \"$TARGET\" \"$f\"" | tee -a "$LOGFILE" | |
| ln -s "$TARGET" "$f" | |
| echo "# [CREATED] symlink $f -> $TARGET" | tee -a "$LOGFILE" | |
| else | |
| echo "# [SKIPPED] Could not decode target for $f" | tee -a "$LOGFILE" | |
| fi | |
| done | |
| echo "Conversion complete. Log saved to $LOGFILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment