Unable to delete a file - BSD

This is a discussion on Unable to delete a file - BSD ; I am a superuser, and unable to delete a file from the drive in FreeBSD. The filename is -1, and no matter how I try to delete it, I get the same error message: rm: illegal option -- 1 usage: ...

+ Reply to Thread
Results 1 to 9 of 9

Thread: Unable to delete a file

  1. Unable to delete a file

    I am a superuser, and unable to delete a file from the drive in FreeBSD.
    The filename is -1, and no matter how I try to delete it, I get the same
    error message:

    rm: illegal option -- 1
    usage: rm [-f | -i] [-dIPRrvW] file ...
    unlink file

    I am not using any options, just "rm -1". Even if I put it in quotes, or
    use wildcards, such as "rm ?1" or "rm *1", I get the same error.
    Attempts to rename it first to something else are futile as well.

    How can I delete this file?

    Marshall

  2. Re: Unable to delete a file

    Marshall Dudley wrote:

    > I am a superuser, and unable to delete a file from the drive in FreeBSD.
    > The filename is -1, and no matter how I try to delete it, I get the same
    > error message:
    >
    > rm: illegal option -- 1
    > usage: rm [-f | -i] [-dIPRrvW] file ...
    > unlink file
    >
    > I am not using any options, just "rm -1". Even if I put it in quotes, or
    > use wildcards, such as "rm ?1" or "rm *1", I get the same error.
    > Attempts to rename it first to something else are futile as well.
    >
    > How can I delete this file?


    Try:

    rm -- -1

    Jim
    --
    'Cloverfield' in nine words: "What is it?!" "We're gonna die!" BOOM!
    Roll credits.

    http://www.ursaminorbeta.co.uk http://twitter.com/greyareauk

  3. Re: Unable to delete a file

    Marshall Dudley writes:

    > I am a superuser, and unable to delete a file from the drive in
    > FreeBSD. The filename is -1, and no matter how I try to delete it, I
    > get the same error message:
    >
    > rm: illegal option -- 1
    > usage: rm [-f | -i] [-dIPRrvW] file ...
    > unlink file
    >
    > I am not using any options, just "rm -1". Even if I put it in quotes,
    > or use wildcards, such as "rm ?1" or "rm *1", I get the same
    > error. Attempts to rename it first to something else are futile as
    > well.
    >
    > How can I delete this file?


    This is probably the all-time most popular question about Unix shells.
    The best answer I've seen is in a newsgroup FAQ. See the first entry in:

    http://www.faqs.org/faqs/unix-faq/faq/part2/

    --
    Lowell Gilbert, embedded/networking software engineer
    http://be-well.ilk.org/~lowell/

  4. Re: Unable to delete a file

    On Tue, 28 Oct 2008 20:41:34 UTC, Marshall Dudley
    wrote:

    > I am a superuser, and unable to delete a file from the drive in FreeBSD.
    > The filename is -1, and no matter how I try to delete it, I get the same
    > error message:
    >
    > rm: illegal option -- 1
    > usage: rm [-f | -i] [-dIPRrvW] file ...
    > unlink file
    >
    > I am not using any options, just "rm -1". Even if I put it in quotes, or
    > use wildcards, such as "rm ?1" or "rm *1", I get the same error.
    > Attempts to rename it first to something else are futile as well.


    It treats -1 as an option since it begins with -.

    Two ways:

    1) rm -- -1
    (the -- says 'ignore all subsequent options and treat them as filenames)

    2) rm ./-1
    (the filename no longer starts with -)

    Just don't ever create a file called -r, then use rm * ...

    --
    Bob Eager
    UNIX since v6..
    http://tinyurl.com/2xqr6h


  5. Re: Unable to delete a file

    Marshall Dudley wrote:

    > The filename is -1


    rm ./-1

    Alphons (that should do the trick)

    --
    If riding in an airplane is flying, then riding in a boat is swimming.
    If you want to experience the element, get out of the vehicle.

  6. Re: Unable to delete a file

    Bob Eager wrote:
    > It treats -1 as an option since it begins with -.
    >
    > Two ways:
    >
    > 1) rm -- -1
    > (the -- says 'ignore all subsequent options and treat them as filenames)
    >
    > 2) rm ./-1
    > (the filename no longer starts with -)


    Another way is to run 'rm' in interactive mode, the OP justs needs to be
    careful about which file(s) gets the "yes" answer...
    With unix, there are so many ways to do stuff, it is hard to forget all
    of them.
    --
    Torfinn Ingolfsen,
    Norway

  7. Re: Unable to delete a file

    Bob Eager wrote:

    > Just don't ever create a file called -r, then use rm * ...

    But touch "-rfv /*" is perfectly fine
    >


  8. Re: Unable to delete a file

    Thanks. That worked.

    Marshall

    Jim wrote:
    > Marshall Dudley wrote:
    >
    >
    >> I am a superuser, and unable to delete a file from the drive in FreeBSD.
    >> The filename is -1, and no matter how I try to delete it, I get the same
    >> error message:
    >>
    >> rm: illegal option -- 1
    >> usage: rm [-f | -i] [-dIPRrvW] file ...
    >> unlink file
    >>
    >> I am not using any options, just "rm -1". Even if I put it in quotes, or
    >> use wildcards, such as "rm ?1" or "rm *1", I get the same error.
    >> Attempts to rename it first to something else are futile as well.
    >>
    >> How can I delete this file?
    >>

    >
    > Try:
    >
    > rm -- -1
    >
    > Jim
    >


  9. Re: Unable to delete a file

    Bob Eager wrote:
    > Just don't ever create a file called -r, then use rm * ...
    >

    It was an accident. The program was generating a file named
    $filename-1, and $filename ended up null because the url it was parsing
    to get the trailing filename had a trailing slash on it.

    Marshall

+ Reply to Thread