3

I wrote a Perl script and fat-fingered the name of my output file inserting a space in the file name, so now I have my_file .txt I have tried the following with no success (and no errors reported):

rm ./my_file\ .txt
rm "./my_file .txt"
find . -inum 123 -exec rm -i {} \;

None of the above removes the file, nor do I receive an error, warning, etc. I own the file, the directory, and have the appropriate permissions. The filehandle is closed and lsof ./my_file\ .txt does not show the file in use elsewhere. My google fu has failed me, so thanks in advance for any help you can offer.

EDIT: output of stat:

$ stat my_file\ .txt
  File: `my_file .txt'
  Size: 4096            Blocks: 8          IO Block: 4096   regular file
Device: fd00h/64768d    Inode: 16613511    Links: 1
Access: (0777/-rwxrwxrwx)  Uid: ( 4939/ abc1111)   Gid: (  100/  ABware)
Access: 2013-07-02 09:27:32.000000000 -0500
Modify: 2013-07-02 10:57:21.000000000 -0500
Change: 2013-07-02 10:57:21.000000000 -0500
An Dorfer
  • 1,178
  • 2
  • 8
  • 14
knobcreekman
  • 133
  • 3
  • 1
    Can you post output of `stat my_file\ .txt` please? All three solutions should be applicable, not receiving an error is especially weird. Is it possible the file gets recreated in the background? – Squeezy Jul 02 '13 at 18:04
  • Have you tried `find . -inum 123 -delete` or just `find my_file*txt -delete` or `rm my_file?.txt`? Anyway, all of the methods you tried should work, is the file perhaps recreated? Has the Perl program exited? – terdon Jul 02 '13 at 18:08
  • @Squeezy: see edit – knobcreekman Jul 02 '13 at 18:11
  • possible duplicate of [how to delete a file with a weird name](http://superuser.com/questions/451979/how-to-delete-a-file-with-a-weird-name) – Ƭᴇcʜιᴇ007 Jul 02 '13 at 18:13
  • @terdon: `find . -inum 123 -delete` worked! thx! make it an answer and i'll mark it. – knobcreekman Jul 02 '13 at 18:15
  • @techie007 not a dupe, the OP tried both of the suggestions from the other question. – terdon Jul 02 '13 at 18:17
  • Perhaps I missed the part where he mentioned he tried the accepted answer of `rm -i *` (sans `find`) from the other question? Still seems like the same question to me, even if it could use newer/different answers. – Ƭᴇcʜιᴇ007 Jul 02 '13 at 18:20
  • Usually, to drive people mad, I add a `space` followed by a `backspace` at the {beginning,middle,end} of a filename. Try to delete it with `rm -i "*my*"` and press `y` at the file you want to get rid off. – ott-- Jul 02 '13 at 18:22
  • 1
    Still, all solutions should have worked. More than curious what caused it to silently fail. – Squeezy Jul 02 '13 at 18:24
  • @techie007 `rm -i *` does not work. It simply does nothing even though globbing in other contexts does expand to the correct file name. terdon's is the only solution I've seen that uses `-delete` instead of `find... -exec` or `find... | someothercommand` , so I don't think this is a dupe. – knobcreekman Jul 02 '13 at 18:25
  • @knobcreekman good to know. :) but still., the question itself still seems the same: "How do I delete a file with a weird name?" In your case the 'weird name' was because of an appended space. But hey, that's why it takes more than 1 vote to close. ;) – Ƭᴇcʜιᴇ007 Jul 02 '13 at 18:27
  • 1
    @Squeezy I'd like to know too. I'm certainly not a *nix pro, nor is it my job to be. But I do like to know why things don't work as expected. – knobcreekman Jul 02 '13 at 18:27
  • Can you provide the perl script, or at least the part creating the file maybe? – Squeezy Jul 02 '13 at 18:29
  • @Squeezy it was just a string literal I threw in real quick before testing something (thus the fat-fingering catastrophe) `open MYFILEHANDLE, ">", "my_file .txt"` – knobcreekman Jul 02 '13 at 18:32
  • `perl -e 'open MYFILEHANDLE, ">", "my_file .txt";'` and subsequent `rm my_file\ .txt` works just fine for me. There must be something special. :D – Squeezy Jul 02 '13 at 18:36
  • @Squeezy I just tried it again using the `perl -e` switch from the shell like you did and it left me with another "unremovable" file like before... that is odd – knobcreekman Jul 02 '13 at 18:41
  • What kind of system are you running? – Squeezy Jul 02 '13 at 18:48
  • Red Hat Enterprise Server – knobcreekman Jul 02 '13 at 19:16
  • Is `rm` an alias on your system? Check with `type rm`. Maybe that is causing the problems... – terdon Jul 03 '13 at 02:20
  • 2
    @terdon I didn't even think of that. I just got back to work and checked it. It is not an alias, but `type` revealed that my system has been modified to point to a homegrown version of `rm`. When I use the path `/bin/rm` it works as expected. The mystery is finally solved! And it took less than 24 hours... good work team :-D – knobcreekman Jul 03 '13 at 12:11
  • Whoever thought it was a good idea to invent a homegrown `rm` should be kept away from the root password. – Kevin Panko Aug 07 '14 at 16:52

1 Answers1

4

The most surefire way to delete things with weird names is to use find's -delete action. For example

find . -inum 16613511 -delete 

or

find . my_file?.txt -delete 
terdon
  • 52,568
  • 14
  • 124
  • 170