Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk3 min

How to Handle Filenames That Start with a Dash in Linux

A filename starting with a dash can look like a command option. Use -- or a path prefix such as ./-name, and use NUL-delimited tools for batches.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.