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:
|Max File Name Length
|255 UTF-16 characters
|8.3 (255 UCS-2 code units with VFAT LFNs)
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
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
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
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.