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.

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.

  • 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. Feb 3, 2012 at 23:20
  • One other options, if you have GNU rm, is rm -i * and answer yes/no to the "delete this file" question... Feb 3, 2012 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. Feb 3, 2012 at 23:39

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";
unlink @jsonPattern;

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

  • You can select your own answer as the correct one, it is the correct way to do it Meta discussion
    – MoonSire
    Apr 9, 2013 at 9:54

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.