Operating System - HP-UX
1834798 Members
2669 Online
110070 Solutions
New Discussion

how to remove directories of name like "-a" & "-".

 
SOLVED
Go to solution
Karthikeyan_5
Frequent Advisor

how to remove directories of name like "-a" & "-".

Hi,

mistakenly some body have created few directories with the name starting with the "-" (minus) sign & "-" itself.....for e.g. -a, -cad, - ......

when i try to remove "-a" dir using the following command:

#rm -rf -a

i am getting the following error message:

rm:illegal option -- a
Usage: rm [-Rfir] file ...

And I am afraid to try the same above command for removing "-" dir because "-" in unix stands for previous dir (i mean successful prev. cd).

Can anyone tell me how to remove the above said directories.....

Thanks in advance.....
12 REPLIES 12
Massimo Bianchi
Honored Contributor

Re: how to remove directories of name like "-a" & "-".

Quote it :)

rm -r "-a"

Massimo
Tom Geudens
Honored Contributor

Re: how to remove directories of name like "-a" & "-".

Hi,
rm -- -a
Will do the trick ...

Regards,
Tom Geudens
A life ? Cool ! Where can I download one of those from ?
Michael Tully
Honored Contributor

Re: how to remove directories of name like "-a" & "-".

Place the directory name in quotes.

$ rm -rf "-a"
Anyone for a Mutiny ?
Tim Adamson_1
Honored Contributor

Re: how to remove directories of name like "-a" & "-".

Hi,

Try the following:

rmdir -- -a
rmdir -- -


Cheers

Yesterday is history, tomorrow is a mystery, today is a gift. That's why it's called the present.
Tom Geudens
Honored Contributor

Re: how to remove directories of name like "-a" & "-".

Hi,
Sorry about that ... should have been
rm -rf -- -a
or
rmdir -- -a

-- ends the commandline options

Regards again,
Tom
A life ? Cool ! Where can I download one of those from ?
twang
Honored Contributor

Re: how to remove directories of name like "-a" & "-".

# rm -r "-a"
john korterman
Honored Contributor

Re: how to remove directories of name like "-a" & "-".

Hi,

# cd
# rm ./-a

will also work. If you want to create the file again in order to try another suggestion, then # touch -- -a

regards,
John K.
it would be nice if you always got a second chance
Simone Benzi_1
Frequent Advisor

Re: how to remove directories of name like "-a" & "-".

Hi,

You ca also easily remove it from the parent directory:

cd ..
rmdir /-a

or from your current directory:

rmdir ./-a

Bye!

Simone
Fragon
Trusted Contributor

Re: how to remove directories of name like "-a" & "-".

For example /somedir/-a,
#cd somedir
#rm -r "./-a"

-ux
blal
Frequent Advisor

Re: how to remove directories of name like "-a" & "-".

Hi

This will also work.

find . -name "-*" -exec rm -r -f {} \;

This will remove all any file or directory starting with "-".


regds
baiju.
Live and let live.
sdip
Advisor
Solution

Re: how to remove directories of name like "-a" & "-".

First try to find out the inode number of that directory by "ls -li" and then execute the following command.
find . -inum -exec rm -rf {} \;
Karthikeyan_5
Frequent Advisor

Re: how to remove directories of name like "-a" & "-".

hi all,

first of all I thank all of you for showing interest......

My problem is solved and i used the following commands:

rm -rf -- -a
rm -rf -- -

or

rm -r "./-a"
rm -r "./-"

or

find . -inum -exec rm -rf {} \;

Where
--> get inode number of that
directory by "ls -li".

Some person has given "rmdir" and if i am correct then this command will be useful or successful only when the directory is empty.

Few more have stated

rm -- -a
and
rm -rf "-a"

Inorder to remove a dir i think we have to use "-r" along with "rm" command in the first and the above second command will give error...

Thank you.......

karthik