Computing.Net > Forums > Unix > How to delete a file that starts with hyphen

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

How to delete a file that starts with hyphen

Reply to Message Icon

Name: arulactive
Date: August 5, 2009 at 03:08:25 Pacific
OS: Windows Vista
Product: Sun microsystems Sun fire v100 550mhz/512kb l2 cache/256mb memory/1x80gb/cd-rom/lan/solaris 8, java system web server
Subcategory: General
Tags: solaris
Comment:

I have a file named "-bas" this was created by one of the scripts. Can somebody help in deleting this file?



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: August 5, 2009 at 07:23:07 Pacific
Reply:

I am having a problem creating a file called -bas. Have you tried something like this:

rm ./*bas

Maybe this discussion removing a - file will help:

To remove a - file, use a path to the file -- either full or relative. Assuming the dash file exists in the mydir directory, provide a full path to the file:

rm /pathto/mydir/-

Or if the file exists in the current directory, provide a relative path:

rm ./-

Use find to remove the file everywhere:

find . -name "-" |xargs rm


0

Response Number 2
Name: arulactive
Date: August 5, 2009 at 08:23:29 Pacific
Reply:

It works!..Thanks nails.


0

Response Number 3
Name: tvc
Date: August 15, 2009 at 12:57:01 Pacific
Reply:

You can also run this trick:

rm -i *bas

Just remember to answer N to any file which you do not want to delete, and CTRL-C when the wanted file has passed (or keep pressing N). This trick would work with any weird character, problem is that you MAY end up making mistakes. Be very careful.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: How to delete a file that starts with hyphen

How to delete a file named -x www.computing.net/answers/unix/how-to-delete-a-file-named-x/3350.html

How to parse a file of 199 col? www.computing.net/answers/unix/how-to-parse-a-file-of-199-col/7250.html

how to replace a file in a .zip fil www.computing.net/answers/unix/how-to-replace-a-file-in-a-zip-fil/7497.html