Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete a file in linux that contains double dash [duplicate]

Tags:

linux

rm

Possible Duplicate:
Unable to remove a special named files in terminal

I feel silly asking, but how can I delete a file in linux named --preserve-permissions?

I tried:

rm "--preserve-permissions"

and

rm "\-\-preserve-permissions"

Neither works. Thanks.

like image 878
Justin Avatar asked Dec 27 '12 10:12

Justin


People also ask

How remove hyphen file Linux?

You can use standard UNIX or Linux rm command to delete a file name starting with - or -- . All you have to do is instruct the rm command not to follow end of command line flags by passing double dash -- option before -foo file name.

What is DASH file in Linux?

Last Updated: November 10th, 2020 by Hitesh J in Linux. In Unix or Linux operating systems, working with dashed filename requires some attention. In some cases, you may need to handle files with a dash (-) as the first character. Because dash (-) is generally used by commands to specify options and arguments.


1 Answers

There are several techniques, but the most straightforward for this kind of filename is:

rm ./--preserve-permissions

For filenames with unprintable or hard-to-decipher characters, use

rm -i *

This prompts with each filename and waits for a y or n whether to delete the file (interactive).

like image 129
wallyk Avatar answered Nov 10 '22 15:11

wallyk