Developer Tools

Characters to Avoid in File Names on Windows, Linux and Cloud Sync

By Raja JahangirPublished December 1, 20264 min read
Infographic: a laptop file manager with colon, question mark, asterisk and quote keys each crossed out in red, a card of what Windows rejects and four steps to clean a file name

Key takeaways

  • Names built only from letters, digits, the period, the underscore and the hyphen work on Windows, Linux, macOS and cloud sync.
  • Windows refuses nine reserved characters, device names like NUL with any extension, and names ending in a space or period.
  • Linux accepts almost anything, but spaces, brackets and leading hyphens break shell commands and scripts that forget quotes.
  • Paste a name without its extension into a slug generator to get a safe version, then add the extension back.

A file name made only of letters A to Z (upper or lower case), the digits 0 to 9, the period, the underscore and the hyphen works on every system. That is the POSIX "portable filename character set". Windows additionally refuses nine characters, < > : " / \ and the vertical bar, ? and *, and a name that ends in a space or a period. Linux refuses only the slash and the null byte, but spaces, parentheses and quotes still break scripts. To turn a messy name into a safe one, paste the part before the extension into our slug generator, copy the result, and add the extension back.

What each system rejects

Where the file lives Not allowed Best avoided
Windows < > : " / \ ? * and the vertical bar; the names CON, PRN, AUX, NUL, COM1 to COM9 and LPT1 to LPT9, even with an extension A space or period at the end of the name
Linux and other Unix systems / and the null byte A hyphen as the first character, plus spaces, quotes and brackets in names used by scripts
Dropbox (all platforms) / and \ < > : " ? *, the vertical bar, a period at the end on Windows, and paths over 260 characters

Two Windows rules surprise people. First, the reserved device names apply with any extension, so Microsoft notes that NUL.txt is treated the same as NUL. Second, the shell and Explorer do not support a name that ends in a space or a period, even though the underlying file system may store one. Dropbox's naming guide goes further and recommends against a space before the extension too, giving a name like "Panda .png" as the example to avoid.

Why spaces and brackets still cause trouble

A Linux or macOS system will happily store photo (1).jpg. The trouble starts when you work with it. In a terminal, a space ends an argument and parentheses are shell syntax, so every command has to quote the name. A loop in a script that forgets the quotes splits the name into pieces and fails on files it cannot find. Browsers download duplicates with exactly this " (1)" pattern, which is why a folder of downloads is a common place to meet the problem.

Leading hyphens are a quieter risk: a file named -r looks like an option to most commands. POSIX recommends that applications avoid filenames starting with a hyphen for this reason.

Table of four messy file names and the clean names the slug generator made from them, beside a laptop showing folders on a tidy desk

Clean a name with the slug generator

The slug generator was built for URLs, and URL slugs follow the same safe set. It removes accents, lowercases the text, and replaces every run of spaces and punctuation with one hyphen or underscore. We ran these names through it with the default settings:

You type Hyphen (default) Underscore, Lowercase off
Q3 report: draft? q3-report-draft Q3_Report_Draft
Invoice #42 / March 2026 invoice-42-march-2026 Invoice_42_March_2026
photo (1) photo-1 Photo_1
Señora Muñoz «notes» senora-munoz-notes Senora_Munoz_Notes

Three things to know before you rename:

  1. Paste the name without its extension. The tool treats a period as punctuation, so "cafe menu.final" becomes cafe-menu-final. Clean the base name, then add .pdf, .jpg or whatever the original had.
  2. Trailing spaces disappear. "Panda " becomes panda, which fixes the space-before-extension problem.
  3. Numbers are kept. The " (1)" duplicate suffix becomes -1, so two copies keep different names. Delete the suffix by hand if you only want one copy.

A naming pattern that stays safe and sorts well

Once the characters are safe, a consistent pattern makes files easy to find:

  • Start with the date as year-month-day, for example 2026-12-01, so files sort in date order.
  • Use one separator. Hyphens are the usual choice for anything that might end up in a URL; underscores suit code and data files.
  • Keep one case. All lowercase avoids two names that differ only by a capital letter, which some systems treat as the same file. The case converter turns a list of names into snake_case or kebab-case in one go.
  • Put the version last, as v2 or v3, not "final" and "final final".
  • Keep names short. Windows editions before Windows 10 version 1607 limit a full path to 260 characters, and later versions need a registry or Group Policy change to lift that limit. Dropbox also asks for paths under 260 characters. Long names inside deep folders reach that limit sooner than you expect.

Renaming many files

The slug generator cleans one name at a time. For a long list, paste all the names into the case converter or the remove duplicate lines tool to tidy and de-duplicate the list, then use your system's batch rename feature or a short script. Test any script on a copy of the folder first, because a rename cannot always be undone.

Sources

Frequently asked questions