Use -- to tell a command that option parsing is finished, or pass the filename as a path such as ./-name. For example, to remove a file named -name in the current directory, run rm -- -name or rm ./-name. These forms prevent the filename from being mistaken for an option.
Why a leading dash causes trouble
Many command-line programs treat an argument beginning with - as an option. A file actually named -name can therefore be interpreted as a command option instead of a filename. The shell passes arguments to the program; the program then decides how to parse them.
As an Amazon Associate I earn from qualifying purchases.
Remove a file whose name starts with a dash
For GNU rm, either end option parsing with -- or include a path prefix:
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →rm -- -name
rm ./-name
The Linux rm(1) manual documents both patterns, using -foo as its example: rm(1), Linux man-pages. GNU Coreutils also documents rm -- -f and rm ./-f. Its manual explains that “Later arguments, if any, are treated as operands even if they begin with ‘-’.” See GNU Coreutils: Common options.
#1 Best Overall
Before running a destructive command, verify that you have identified the intended file and directory. These examples remove the specified file; they do not make deletion reversible.
Copy, move, or rename the file
The same approach works for the source operand of GNU cp and mv:
cp -- -name destination
mv -- -name destination
mv -- -old-name new-name
You can instead use ./-name as the source path when the file is in the current directory. GNU Coreutils documents -- as its option-list delimiter; for a different utility or platform, consult that command’s manual rather than assuming it handles the marker the same way.
With mv, also consider how the destination is interpreted. If you need the last operand treated as the exact destination rather than as a directory into which the source should be moved, GNU mv provides -T (also spelled --no-target-directory).
Quoting does not replace the option delimiter
Quotes protect shell-special characters and prevent word splitting or expansion, but they do not change how a program interprets an argument that starts with a dash. For example, use rm -- '-name' when quoting is needed as well as an option delimiter. For a current-directory file, rm './-name' uses a path prefix; the quotes are only needed if the path contains shell-special characters or whitespace.
Handle multiple filenames safely
For a simple glob in the current directory, rm -- * ensures that expanded names beginning with a dash are treated as operands by GNU rm. The shell’s * pattern does not match hidden names by default. Inspect what a pattern expands to before using it with a destructive command.
Rank #4
For scripts or batches of arbitrary names, avoid parsing ls output or splitting names on spaces or newlines. A filename can contain spaces, tabs, and newline characters, so newline-separated text is not a reliable filename format. GNU guidance recommends NUL-delimited input, such as:
find . -type f -print0 | xargs -0 command
Replace command with the intended operation and its arguments, ensuring that the receiving utility’s option parsing is handled too. GNU documentation covers safe file-name handling; the find(1) Linux man-page describes find parsing and filename handling.
Best Value
Which approach should you use?
| Situation | Approach | Why |
|---|---|---|
| One file in the current directory | rm -- -name or rm ./-name |
-- ends option parsing where supported; ./ makes the argument a path rather than a leading-dash name. |
| Copying or moving a dash-leading source | cp -- -name destination or mv -- -name destination |
The marker separates options from operands for GNU Coreutils. |
| Quoting is also needed | rm -- '-name' |
Quoting handles shell interpretation; -- handles the program’s option parsing. |
| Processing many arbitrary filenames | find ... -print0 with xargs -0 |
NUL delimiters avoid confusing filename contents with separators such as spaces or newlines. |
The -- examples here follow GNU Coreutils and the cited Linux man-pages. Utilities can differ, so check the target command’s own manual when portability matters.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




