Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Removing weird file names

  1. #1

    Default Removing weird file names

    It's my own inability to refrain from experimenting that causes this problem so please bear with me. I have file called: -ioP

    This just happens to be the options I was using for a grep command when things went south. Anyway, none of these will remove the file:

    rm '-ioP'
    rm \-ioP
    rm \\-ioP
    rm '\-ioP'

    and perhaps a few others I tried. Does anyone have a trick or two for weird files like this?

  2. #2
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: Removing weird file names

    rm ./-ioP

  3. #3

    Default Re: Removing weird file names

    That worked, thanks!

  4. #4
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: Removing weird file names

    I hope you understand why. ./ is not an escape code. It's just a way of making sure that the first character of the argument is not -.

  5. #5
    palladium NNTP User

    Default Re: Removing weird file names

    ken yap wrote:
    > I hope you understand why. ./ is not an escape code. It's just a way of
    > making sure that the first character of the argument is not -.



    Q: would

    rm ?ioP

    do it also?

    however, if i were gonna do that i'd first do

    ls ?ioP

    to see if *maybe* their might also be in that directory some files i
    wanted to keep, like:

    pioP
    PioP
    ?ioP
    ioP
    etc

    *or* do

    rm -i ?ioP

    and expect to have to answer 'yes' once or more..

    --
    palladium

  6. #6
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: Removing weird file names

    The answer depends on whether ? substitution happens before grep sees the argument. What do you think?

    Incidentally another way of doing it is:

    rm -- -ioP

    where the -- signifies end of options and after that - is not significant as the first character. And both methods are explained in the man page for rm.

  7. #7
    palladium NNTP User

    Default Re: Removing weird file names

    ken yap wrote:
    > The answer depends on whether ? substitution happens before grep sees
    > the argument. What do you think?


    hmmmmm...(see, i'm not a real guru and i therefore didn't know) does
    grep have a chance to get in the act if the following is issued:

    rm ?ioP

    are you saying that the rm command ("behind the scenes") first calls
    grep to filter the list to act on and then performs the remove
    actions?? interesting...


    > Incidentally another way of doing it is:
    >
    > rm -- -ioP


    thanks, read that and promptly forgot it..
    (maybe it will 'stick' now)

    --
    palladium

  8. #8
    Join Date
    Jun 2008
    Location
    Groningen, Netherlands
    Posts
    20,043
    Blog Entries
    14

    Default Re: Removing weird file names

    @palladium: the 'grep' probably was from the original command. I've done 'greps' redirected to a filename which was based on the expected result of the 'grep'. One result was a filename beginning with "-" since there were no results from 'grep'. IIRC I was able to move the -file to a new folder, then removed the folder by force( too lazy for 'man rm', thinking I knew all that.....).
    ° Appreciate my reply? Click the star and let me know why.

    ° Perfection is not gonna happen. No way.

    https://en.opensuse.org/openSUSE:Board#Members
    http://en.opensuse.org/User:Knurpht
    http://nl.opensuse.org/Gebruiker:Knurpht

  9. #9
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: Removing weird file names

    Quote Originally Posted by palladium View Post
    rm ?ioP

    are you saying that the rm command ("behind the scenes") first calls
    grep to filter the list to act on and then performs the remove
    actions?? interesting...
    Sorry, I meant rm, not grep, in that command.

    No, the shell expands the ?ioP to -ioP and this is what rm sees, and it's as you typed -ioP to rm and ioP are treated as options.

  10. #10
    palladium NNTP User

    Default Re: Removing weird file names

    having just reviewed the last few i am now more confused than ever..

    i _think_ the answer to my question would

    rm ?ioP

    do the same as your

    rm ./-ioP

    would be "yes, if used alone (as did the OP) and not pipelined in with
    grep (or other commands) which might jumble it....or, in other words
    your would always work (and is therefor the better way)

    am i right? and i will say: thanks for the better way which will
    always work!!

    --
    palladium

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •