Authors Top

If you have a few years of experience in the Linux ecosystem, and you’re interested in sharing that experience with the community, have a look at our Contribution Guidelines.

1. Overview

In Unix-based systems, there is a limit on the length of filenames. This limit is different on different file systems.

In this tutorial, we’ll learn how to find the limit on different file systems. Additionally, we’ll create a file with a long name to confirm how the limit works.

2. File Name Length Limits and Unix File Systems

Most Unix file systems have similar filename length limits:

File System Max File Name Length
BTRFS 255 bytes
exFAT 255 UTF-16 characters
ext2 255 bytes
ext3 255 bytes
ext3cow 255 bytes
ext4 255 bytes
FAT32 8.3 (255 UCS-2 code units with VFAT LFNs)
NTFS 255 characters

However, since the Unicode representation of a character can occupy several bytes, the maximum number of characters that comprise a path and filename can vary.

Further, the limits remain the same whether the filename contains an extension or not. We can take a look at a more exhaustive list of the filename and path limits depending on the file system.

We can also have extensions on our file system that change the maximum length limit. A good example of this is eCryptFS which utilizes part of the lower filename to keep metadata and sets the limit of a filename to 143 characters.

3. Finding the Limit

Linux has a handy command called getconf for querying system configuration variables.

We can run it to find the filename length limit:

$ getconf -a | grep -i name_max
NAME_MAX                           255
_POSIX_NAME_MAX                    255
LOGNAME_MAX                        256
TTY_NAME_MAX                       32
TZNAME_MAX                         
_POSIX_TZNAME_MAX                  
CHARCLASS_NAME_MAX                 2048
HOST_NAME_MAX                      64
LOGIN_NAME_MAX                     256

Here, the NAME_MAX configuration represents the filename length limit.

Similarly, we can find the path length limit by modifying the last part of our previous command:

$ getconf -a | grep -i path_max
PATH_MAX                           4096
_POSIX_PATH_MAX                    4096

4. Confirming the Limits

Let’s use the standard touch command to try and create a file with a name containing 258 characters, i.e., three characters more than the limit of 255:

$ touch abcabcabcabcabcabcabc...other characters omitted....abcabcabc

Here’s the response we get:

touch: cannot touch 'abcabcabcabcabcabcabc...other characters omitted....abcabcabc': File name too long

5. Conclusion

In this article, we learned how to check both filename and path limits on different Linux file systems. We also tried to create a file that surpassed the limit to see the error we got.

Authors Bottom

If you have a few years of experience in the Linux ecosystem, and you’re interested in sharing that experience with the community, have a look at our Contribution Guidelines.

Comments are closed on this article!