10

I want to rename file with weird name to something reasonable, however I'm not able to :/

$ mv *_000c.jpg 000c.jpg
mv: cannot move '?j?Z?R?C1_000c.jpg' to '000c.jpg': No such file or directory

I've tried using inode number as was recommend in few places on the internet:

$ ls -il *000c.jpg
ls: '?j?Z?R?C1_000c.jpg': No such file or directory
213915 -rw-r--r-- 1 wolf wolf 794655 Jul 21  2012 '?j?Z?R?C1_000c.jpg'
$ find . -inum 213915 -print0 | xargs -0 -I '{}' mv '{}' 000c.jpg
mv: cannot move './?j?Z?R?C1_000c.jpg' to '000c.jpg': No such file or directory

What should I do?

  • 1
    What is the output of a simple ls in that directory? Is the file shown as a regular file? I am asking to make sure that the No such file or directory is a globbing error and not indicative of a damaged file system. – terdon Apr 12 '17 at 13:50
  • 1
    I wonder if the filesystem needs to be run through fsck? I may be corrupted. How did the file acquire that name? – Kusalananda Apr 12 '17 at 13:50
  • 1
    @Mioriin The question marks in the filename are (or may well be) placeholders for characters that can't be displayed. (one reason to never parse the output of ls) – Kusalananda Apr 12 '17 at 13:54
  • 1
    This might be a terminal font issue. It's showing ? for letters that it can't display. Try switching to a fully unicode font. – Mioriin Apr 12 '17 at 13:55
  • 5
    @Mioriin Whether or not the filename can be displayed is a bit of a red herring in this case I think. What's odd is that the shell is able to expand *_000c.jpg but that mv then can't process the file. This is, IMHO, indicative of a corrupt filesystem. ... or possibly of a filesystem that's mounted on a network share that's gone away (with the directory entries still cached), or something. – Kusalananda Apr 12 '17 at 13:59
16

Summary of relevant comments:

Unix file systems allows any character in a file name apart from \0 (nul) and / (forward slash). The fact that ls shows question marks is only because it can't display some of the characters of the filename in the current locale (which is one of the reasons why you should avoid parsing the output of ls).

However, with a Samba share, you apparently have more strict requirements on filenames than on a standard Unix filesystem.

Since the file had a name that was "illegal" on your intermediate Samba share, the file was inaccessible by its correct name on the machine mounting the share.

The mv didn't work since the name returned from the Samba share for the expansion of the globbing pattern was not the actual name of the file on the hosting filesystem, only Samba's own mangled version of the name.

Your solution was to log into the server that actually hosted the file (on a filesystem with less restrictive naming rules than Samba) and change the name of the file there. This was the correct course of action.

See also the Unix&Linux chat about this question.

-2

Before I learned about quoting in unix shells, I would use emacs' dired mode to rename or delete hard-to-match files. You simply open the directory in emacs:

emacs -q .

... then you can use the arrow keys to navigate to the file you want to modify and rename the file with R. ? will give you the list of available commands (you can delete files that are hard to match too).

Then you just C-x C-c your way out of emacs and you're done.

-3

Often with unusual filenames you can add "./" before the filename and Linux will properly recognize it. For example: $ ls ./?j?Z?R?C1_000c.jpg

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.