“mv” file with garbled name by inode number?

I have several files with encoding issues in their file names (German umlauts, burned on CD with Windows, read by Windows and synced to Linux with Seafile. Something, somewhere went wrong…).
Bash and zsh only show “?” instead of umlauts, stat shows something like

$ stat Erg�nzung.doc 
File: ‘Erg344nzung.doc’
Size: 2609152         Blocks: 5096       IO Block: 4096   regular file
Device: 806h/2054d      Inode: 12321475    Links: 1

I can enter the filename only with autocompletion. How do I rename the file? The affected files seem to be unreadable by LibreOffice (or other programs for other file types), they complain about “No such file or device”.

I was thinking about mv --by-inode 12321475 Ergänzung.doc, but there’s no --by-inode switch for mv. What else can I do?


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You could try:

find . -inum 12321475 -exec mv {} new-filename ;

find . -inum 12321475 -print0 | xargs -0 mv -t new-filename

Generally I prefer xargs over exec. Google for why. It’s tricky though. See Find -exec + vs find | xargs. Which one to choose?

Method 2

There is a utility convmv for this type of problem. It allows you to change
the encoding of a filename from eg windows cp1256 to utf8, etc.

Method 3

Just for the record, the correct xargs -0 usage is:

find . -inum 12321475 -print0 | xargs -0 -I '{}' mv '{}' new-filename

but as already pointed out it wasn’t necessary anyway.

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments