"mv" file with garbled name by inode number?
Solution 1
You could try:
find . -inum 12321475 -exec mv {} new-filename \;
or
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?
Solution 2
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.
Solution 3
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.
Related videos on Youtube
Jasper
Updated on September 18, 2022Comments
-
Jasper over 1 year
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: ‘Erg\344nzung.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 formv
. What else can I do?-
Admin over 8 yearsUmm... you already figured out how to do it with
stat
; just do the same withmv
. -
Admin over 8 yearsI was sure that I tried this and got some error. Now it seems to work. But the
find -inum
-way is more reliable/easier if there are multiple files with the same prefix. -
Admin over 8 years
-
Admin over 8 yearsSee also for example How to remove a file where the file name has utf-8 character issues.
-
Admin over 8 yearsYou said you can enter the filename with autocompletion. So why not
mv Erg<tab> Ergnzung.doc
? -
Admin over 8 years@immibis Consider a directory with many files sharing the same prefix.
-
-
Jasper over 8 yearsI tried, and it worked (with the
-exec
option, didn't try thexargs
command) -
G-Man Says 'Reinstate Monica' over 8 yearsWith
xargs -0
, don’t you needfind …
-print0
? -
Michael Durrant over 8 yearsprobably. like that ^ ? or please edit to correct syntax
-
Avindra Goolcharan over 2 yearsThis one is the only solution on the page that worked