One fun aspect of using any Linux operating system distribution is its ability to transform us into computing wizards. With Linux, its open-source nature makes it possible to break and/or create any logical computing rule(s). Filenames’ length and limit fall under such computing rules.
Since Linux is part of the Unix-based systems, the file name length associated with this operating system has a limit. The length limit of filenames under a Linux operating system depends on the filesystem in question.
This article will determine filename length on different Linux filesystems. Afterward, we will look at the possible limits associated with the filename length.
Filesystems’ File Name Length Limit
The following is a summary of filename length limits found in major Unix file systems.
|File System||Maximum File Name Length|
|exFAT||255 UTF-16 characters|
|FAT32||255 UCS-2 code units with VFAT LFNs|
However, since several bytes can be assigned to a single character’s Unicode representation, the maximum characters representing a filename and/or the path to the actual file tend to differ. The file name limit does not change regardless of whether the filename is associated with an extension or not.
The Linux file system has a strong bearing on filename limits. For instance, file system extensions can alter the maximum filename length limit e.g. the case with eCryptFS.
Finding File Name Length Limit in Linux
To find the file name length limit of all the files that can be created and stored on your Linux-powered computer, we will use the getconf command-line utility, which is effective in querying system configuration variables. We can use it together with the grep command to get the set filename length limit on our Linux system.
$ getconf -a | grep -i name_max
The output NAME_MAX denotes the filename length limit (255) or maximum filename length the Linux system can assign.
If you are interested in the path length limit, the getconf command to execute is as follows:
$ getconf -a | grep -i path_max
Confirming Filename Length Limit
Through the getconf command, we have confirmed that the file name length limit on our Linux OS distribution is 255 characters. Let us try to create a file via the touch command with a file name length of 260 characters (5 characters more than the 255 characters limit).
$ touch Abababababababababababababakakakakakakakaklalalalalaalpqpqpqpqwuwuwuwueehehehehndndndndnkfkfkfkfknbnbnbnvvhvhvhdhdhdhshshshahahahororroojwjwjwnenenenenenemxmxmxmncncncncncnbvbvbvbvbvldldldldldkdkdkdkdjdjdjdhdhdhdgdgdgdfdfdfddsdsdsdadadadqpqpqoqoqoqiqiqiqiuququ
As per the above screen capture output of executing the touch command, we cannot create a file name length of 260 characters because it exceeds the filename length limit of 255 characters.
If we reduce the filename length to the specified limit (255 characters), we should be able to create our file.
$ touch Abababababababababababababakakakakakakakaklalalalalaalpqpqpqpqwuwuwuwueehehehehndndndndnkfkfkfkfknbnbnbnvvhvhvhdhdhdhshshshahahahororroojwjwjwnenenenenenemxmxmxmncncncncncnbvbvbvbvbvldldldldldkdkdkdkdjdjdjdhdhdhdgdgdgdfdfdfddsdsdsdadadadqpqpqoqoqoqiqiqiqi
The NAME_MAX parameter value used by the getconf command specifies the filesystem-assigned filename length limit. Trying to redefine this limit (NAME_MAX) would imply rewriting the entire Linux filesystem source code; with inclusion to the disk structure, before using it.
In short, you will need to be a kernel hacker with mastery of C programming language for this implementation to be possible.
The system /usr/include/linux/limits.h file further highlights the discussed filename length limit.
$ cat /usr/include/linux/limits.h
You might also like to read related following articles:
- How to Find Longest Line(s) in a File in Linux
- How to Get Filename from the Full Path in Linux
- How to Remove Spaces from Filenames in Linux
We have understood how the filename length limit works in Linux and the implication of changing it.