Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

While developing a server-side application, I accidentally created a couple of files that are named similar to this:

<?php echo $_GET[\'team\'] ?>files.json

Even after I add the necessary backslashes to try to rm those files, Terminal says those files don't exist. My FTP GUI will not delete them either.

I'd appreciate help with how to deal with this situation — I couldn't find anything via Google or Stack Overflow.

share|improve this question

2 Answers 2

One common approach is to use something like Perl or Ruby to delete the file:

perl -e 'unlink("random crazy file")'
ruby -e 'File.unlink("random crazy file")'

That avoids the whole shell thing.

The other easy way to do it, with an interactive shell like bash, is to type rm fi, hit tab, and let bash complete the filename for you. That quotes well.

share|improve this answer
    
Unfortunately none of those solutions work on that filename. Even rm's autocomplete fails on its own suggestion. The perl & ruby options work on regular filenames but go into some new command line mode on the file I want to remove. –  james_womack Feb 3 '12 at 23:20
    
One other options, if you have GNU rm, is rm -i * and answer yes/no to the "delete this file" question... –  Daniel Pittman Feb 3 '12 at 23:23
    
— thanks for the help. Your answer did lead me to use perl even though that's not what I'd wanted to use. –  james_womack Feb 3 '12 at 23:39
up vote 0 down vote accepted

I could have used a more precise pattern, but this is what I did:

I ended up backing up my legitimate JSON files and creating a perl script in a subdirectory that would delete all the JSON files in that directory:

$filepath= "../*.json";
@jsonPattern=glob($filepath);
unlink @jsonPattern;

Then I ran that by cd-ing into that subdir and entering perl nameOfMyScript.perl

share|improve this answer
    
You can select your own answer as the correct one, it is the correct way to do it Meta discussion –  MoonSire Apr 9 '13 at 9:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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