What is the maximum filename character length of files in OS X?
Of secondary importance is whether some characters are allowed/disallowed in addition to any overall length restrictions.
From the font of all knowledge, the maximum file name size in the default HFS+ file system is 255 UTF-16 encoding units, so basically 255 characters. Technically, any unicode character can be used, but this may be practically limited by the application you are using - for example, the /
character is used to delineate directories in pathnames, so you may not be allowed to name a single file stuff/things.txt
, as this means "the file things.txt
in the stuff
directory" to the operating system. There are ways of "escaping" characters like /
in filenames, but for general use it's discouraged.
/
is not true (10.6 here). What you can't use is :
(old HFS separator), at least in the Finder. Funny thing is that /
is represented as :
at the shell level. Another strange limitation is that the path length is limited by 1024 bytes or UTF-8 chars, not sure which. This isn't enforced by Finder and can lead to strange behaviour.
Commented
Mar 24, 2013 at 21:11
:
is forbidden on HFS and HFS+ but most UNIX folk are used to automagic substitution of / for : and vice versa and don't realize HFS's internal storage uses : to separate directories from file names.
pathchk -p
is handy for running these sort of portability checks.
touch 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345
works fine. But touch 12345678901234567890....6
with one more character throws: File name too long
. FYI touch
just creates an empty file, or actually sets the existing file's time_modified
to now.
Commented
Jan 5, 2018 at 17:27
Yes - you should keep file names to 255 characters but paths can be longer but not as long as some other unix allows.
The desktop OS X supports ten major filesystems (HFS, HFS Plus, UFS, WebDAV, UDF, FAT, SMB/CIFS, AFP, NFS, and FTP) with several variants of some of these. See table 1 at developer.apple.com's article below for details:
The system default filesystem, HFS plus supports filenames of 255 UTF-16 encoding units and the only reserved character is :
which is used internally to denote a directory change as opposed to /
which normally is reserved to signify a directory change rather than belonging to the name of the file. (ok - I believe 0x00, the null character also is forbidden in HFS+)
By convention, software should use file handles and are responsible for allocating enough space to contain an arbitrarily long file path if it doesn't use standard API for navigating the filesystem structure to locate a 255 length filename.
/
. Xcode also shows the file name as /
. VS Code and ls
both show the name as :
.
Commented
Mar 8, 2021 at 12:05