Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wrote a program that uses POSIX memory-mapping function (mmap)

The program takes a file (a.dat) and memory-maps it for reading/writing.

Due to errors in the program, every time I run the program a file with some weird names (e.g., ?d?P?^z??d?P?^z?) is created. The error is resolved but I am not able to delete the files.

I am not able to delete it either using command line or by select/deleting from window manager.

So how should I delete it? I'm using Ubuntu 11.04.

share|improve this question

migrated from stackoverflow.com Jul 22 '12 at 1:01

This question came from our site for professional and enthusiast programmers.

    
Even if you cannot easily type the filename, deleting it from a graphical file manager should work fine. What error are you getting? – Thomas Jul 15 '12 at 7:24
1  
@Aditya, I have no problem deleting such files from the command line when escaping their names with single quotes (rm '?d?P?^z??d?P?^z?'). Did you try that? – Frédéric Hamidi Jul 15 '12 at 7:26
    
deleting from graphical window manager just says cannot delete file 'filename'. @Frédéric Hamidi Thanks for helping me delete one file. But the other one with name '?m?P???)?m?P???)' isnt getting deleted ... The error message says "rm: cannot remove `?m?P???)?m?P???)': No such file or directory" – A. K. Jul 15 '12 at 7:31
1  
@Aditya, that other file must have non-printable characters in its name. Try the following steps: 1/ Move all the valid files out of that folder, 2/ Issue rm * inside the folder. – Frédéric Hamidi Jul 15 '12 at 7:34
1  
When typing the file name try to start with quotes, then use auto completion as soon as it works (after one or two characters). Auto completion would be hitting the [tab] key to make the shell auto complete the name. This way you might be more successful to correctly escape the names. – arkascha Jul 15 '12 at 7:34
up vote 15 down vote accepted

rm -i * will prompt you to delete each file. You can and should change '*' to a narrower match if there are a lot of files.

I've used that in the past and it works until you hit a special character or 2 that it does not like.

share|improve this answer
    
it worked. thanks – A. K. Jul 15 '12 at 7:54
    
This doesn't work for a file named -d for example. – SCO Feb 6 '15 at 9:29
    
@SCO If it doesn't work for you and depending on your version of rm, you can do rm -i -- * The -- tells some versions of rm there are no more command line line switches after the -- and to treat further args as filenames. – JimR Aug 18 '15 at 21:39

Another way is to remove the file by inode (see here)

share|improve this answer
    
Sounds like a good idea...thanks – A. K. Jul 15 '12 at 12:51

you can use ls -li to show all files by their inode. Then run find . -inum ${INODE_NUM} -delete to remove the file. I added -maxdepth 1 to my find just to be safe.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .