Characters to Avoid in File Names Across Mac, Windows, and Linux
The safest file names use only letters, digits, the period, the underscore, and the hyphen. Beyond that set, what breaks depends on which system the file passes through: a name that is fine on Linux can fail on Windows, or look different in the Finder on a Mac.
Quick summary
- Windows rejects nine characters (
< > : " / \ | ? *), control codes, and a handful of reserved device names. - On a Mac, the Finder won't take a colon, while Terminal won't take a slash.
- Linux and other Unix-like systems prohibit only the slash and the NUL character.
- The one set every system accepts is the 65-character POSIX portable set: A to Z, a to z, 0 to 9, period, underscore, hyphen.
The list: characters and names to avoid
1. The nine Windows reserved characters
Microsoft's documentation allows any character in the current code page except these: < > : " / \ | ? *. It also rules out "any other character that the target file system does not allow." These are the characters that most often bite people who name files freely on a Mac or Linux box, then copy them to a Windows machine or a shared drive. The Win32 naming rules are the reference.
Bad: meeting: Q4 plan?.md
Good: meeting-q4-plan.md2. The slash and the NUL character
These two are the only characters that Unix-like file systems prohibit. The slash separates path components, and NUL ends a string. Windows rejects both as well, so they are off limits everywhere. Wikipedia's overview of file names summarizes the Unix rule in one line.
3. The colon on a Mac
Apple's Mac Help says you can't include a colon when you rename an item in the Finder, and that some apps may not allow a slash. Underneath, macOS has two layers. An Apple engineer explained on the developer forums that in Terminal, file names can't contain a forward slash, while in the Finder they can't contain a colon, and "the system swaps slashes and colons as the name moves between those layers." A file that a Unix tool creates as hh:mm.txt appears in the Finder as hh/mm.txt, and the reverse. See Apple's rename guide and the developer forum thread.
The practical lesson: a colon in a time stamp (14:30) looks fine in Terminal and is rejected by Windows. Write 1430 or 14-30 instead.
4. Control characters and invisible characters
Microsoft excludes characters with values 1 through 31 as well as zero. Nobody types those on purpose, but invisible characters can sneak in through copy and paste and make two names look identical when they are not. Our guide to invisible characters shows how to spot them.
5. Windows device names
Windows reserves CON, PRN, AUX, NUL, COM1 through COM9, and LPT1 through LPT9. Microsoft adds that you should avoid these names followed immediately by an extension: "NUL.txt and NUL.tar.gz are both equivalent to NUL." A note called aux.md is legal on a Mac. It becomes a problem the moment it lands on a Windows drive.
6. A trailing space or period, and a leading period
Microsoft says not to end a name with a space or a period. The underlying file system may support such names, but the Windows shell and user interface does not. A leading period is allowed (.temp is fine), but on a Mac the Finder won't let you start a name with one when renaming, and such files are treated as hidden on Unix-like systems. Neither suits a file you want people to find.
7. A leading hyphen
The POSIX portable set includes the hyphen, but with a catch: it should not be the first character of a name. A command-line tool will read -notes.txt as an option, not a file. The same care applies to scripts, so if you write a shebang line for a script you plan to run from a shell, give the file a plain name.
8. Names that differ only by case
Not a forbidden character, but it fails in the same way. Microsoft says not to assume case sensitivity: OSCAR, Oscar, and oscar are the same name on Windows. HFS+ and APFS on macOS are case-insensitive but case-preserving by default. Unix-like file systems have traditionally been case-sensitive. Put Notes.md and notes.md in one folder on Linux, and they collide when you move the folder to a Mac or Windows machine.
A note on length
Windows paths were limited to 260 characters (MAX_PATH) before Windows 10 version 1607. Keep names short and folder trees shallow, and older setups won't trip on it.
A safe set that works everywhere
POSIX defines a portable filename character set of 65 characters: 26 uppercase letters, 26 lowercase letters, 10 digits, and three punctuation characters, the period, the underscore, and the hyphen. The portable character set page notes that people recommend sticking to it even on systems that allow more. Add two habits and you have a naming rule that holds up across all three systems:
- Use lowercase with hyphens between words.
- Don't start with a hyphen or a period, and don't end with a period or a space.
Bad: Trip Notes: Day 1?.txt
Good: trip-notes-day-1.txtPutting this into practice with Carets
Carets keeps your notes and code as plain text files, so the names you give them follow you everywhere: to a Windows machine, a Linux server, or a shared folder. So it's worth settling a naming rule early. Name files with the safe set above, and use projects and tags in Carets for the context that you might otherwise cram into a name, such as a date, a client, or a status. Fewer odd characters in the name means fewer ways for a sync or copy to go wrong.
Carets is a native editor for iPhone, iPad, and Mac, with Markdown, plain text, and code in one place and syntax highlighting for config and code files. When you need to move text around the system, pbcopy and pbpaste pair well with it on a Mac.
Get Carets on the App Store for iPhone, iPad, and Mac
Frequently Asked Questions
Which characters are illegal in file names on every system?
The slash and the NUL character. Unix-like systems reject them, and so does Windows. If you stay with letters, digits, the period, the underscore, and the hyphen, you also avoid the rest of the Windows reserved set.
Can I use a colon in a file name on a Mac?
Not in the Finder, which doesn't accept a colon. Terminal does, and the Finder then shows that colon as a slash. Either way the name breaks on Windows, so leave the colon out of anything you share.
Why does a file named NUL.txt cause trouble on Windows?
Windows reserves device names such as CON, PRN, AUX, NUL, COM1 to COM9, and LPT1 to LPT9. Microsoft says a reserved name followed by an extension is treated the same as the bare name, so NUL.txt is equivalent to NUL.
Does uppercase versus lowercase matter in file names?
Yes, when files move between systems. Windows says not to assume case sensitivity, macOS file systems are case-insensitive but case-preserving by default, and Unix-like systems are traditionally case-sensitive. Two names that differ only by case can collide when you copy them from one to another.