#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2009
    Location
    United States
    Posts
    118
    Rep Power
    135

    Deleting file with back slash in name


    I somehow created a file called "\ --directory" in the / directory of my server. I created it trying to create a tar file from the command line...I'm not sure what I had typed exactly since I did it a few hours ago.

    I can't figure out how to delete it, no matter what I try it says "no such file or directory".

  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,448
    Rep Power
    1751
    When trying to deleet files with bizarre names, containing special characters I tend to tread carefully and use the ls command first to find out just what the shell will accept. Once I can list the file I will change the ls to rm. Anyway, try:

    Code:
    rm "\\ \-\-directory"
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2009
    Location
    United States
    Posts
    118
    Rep Power
    135
    That doesn't work either. It simple gives me
    Code:
    rm: cannot lstat `\\ \\-\\-directory': No such file or directory
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,448
    Rep Power
    1751
    I hate trying stuff like this ...! As I said, messing about with an ls command can work wonders ... sometimes you need to 'quote' spaces (such as (\ ), sometimes having them in quotes (" ") is enough.
    What do:
    Code:
    ls "\\ *"
    ls "\\\ *"
    ls "*directory"
    return?
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  8. #5
  9. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,439
    Rep Power
    4539
    If the file is named
    \ --directory
    then use this to remove it
    rm "\\ --directory"
    Also, if you have mc installed on your linux box you can let mc do the hard work of parsing the filename, you just have to arrow the selection bar over the offending file and delete it.
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2009
    Location
    United States
    Posts
    118
    Rep Power
    135
    I went the MC route (I've never heard of this, so thanks!).

    Even
    Code:
    rm "\\ --directory"
    didn't work. But it's fixed now, again many thanks guys.
  12. #7
  13. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,439
    Rep Power
    4539
    I find mc indispensable for command-line work. It's the first thing I add on a new linux system.

    You might have had a non-printing character in your filename. I once had a filename that had embedded a couple ctrl-H (backspace) that hid the complete filename. The cursor backed up and overwrote a couple characters that you couldn't see.
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester

IMN logo majestic logo threadwatch logo seochat tools logo