1

I have these two files in my home directory that I am unable to delete:-

-rw-rw-r-- 1 steve steve       20551 Jan 27 23:51 \home\steve?esult_picture.png
-rw-rw-r-- 1 steve steve       22238 Jan 27 23:54 \home\steve?esult.png

The error messages are:-

rm: cannot remove 'homesteve?esult_picture.png': No such file or directory
rm: cannot remove 'homesteve?esult.png': No such file or directory

chmod gives a very similar error

touch '\home\steve?esult_picture.png'
sudo rm -f '\home\steve?esult_picture.png'

touch '\home\steve?esult.png'
sudo rm -f '\home\steve?esult.png'

does not remove them either.

I'm fairly sure they were created in error using a python script.

Using Windows Explorer to view the smb share they are called _1UPF8~X.PNG and _UYBX6~Q.PNG and are viewable as pictures as one would expect. I can't do anything else with them though due to lack of appropriate permissions.

Any idea how I can remove them?

Steve

Steve W
  • 11
  • 4
  • what is your OS? Can you post command that result in first error message? (`rm: cannot remove 'homesteve?esult_picture.png': No such file or directory`) – aaaaa says reinstate Monica Feb 01 '18 at 01:27
  • 1
    Possible duplicate of [How to delete file containing special characters in Linux?](https://serverfault.com/questions/204643/how-to-delete-file-containing-special-characters-in-linux) – Jenny D Feb 02 '18 at 10:02

4 Answers4

2

The question mark shown by ls is probably not a real question mark in the file name, but an unprintable character. Try using ls -b which prints such unprintable characters as their C-style escape; e.g. \t for a tab.

You could also simply try rm \home\steve?esult.png as the question mark will match one character (no matter what that character is). However the backslash needs to be doubled as now it's trying to assign special meaning to the following character.

So this should work:

rm -f \\home\\steve?esult_picture.png
rm -f \\home\\steve?esult.png

Alternatively, this can also be useful:

rm -fi *png

or, if there are many files in the directory:

rm -fi *home*steve*esult*.png

The -i means to prompt before each removal; only respond with y to the files you want to remove.

wurtel
  • 3,864
  • 12
  • 15
0

You will need to use double quotes to delete them:

rm -f "\home\steve?esult_picture.png"
rm -f "\home\steve?esult.png"

The backslashes are escape characters indicating that the following characters have special meanings. Double quotes will indicate that they are part of the filename and allow you to delete the files with the rm command.

Nasir Riley
  • 2,137
  • 9
  • 10
0

It is good to master the rm command to be able to use it for any kind of strange filenames (like ones starting with - for example), and you could learn to do that from other answers here.

There is also another solution, that can be helpful in many other cases. Install the tool called mc aka Midnight Commander. It is a file browser running in the terminal, so you can list files, highlight the one you want to operate on, and then just hit F8 to delete it. Whatever characters are in the name.

See https://midnight-commander.org/

Patrick Mevzek
  • 9,921
  • 7
  • 32
  • 43
0

Thanks for the responses, Ive managed to get rid of them using a Remote Desktop and selecting the files which must have just sorted out the odd characters.

Steve W
  • 11
  • 4