Home Linux Commandline Tips How to Find and Limit File Name Length in Linux

How to Find and Limit File Name Length in Linux

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
ext2 255 bytes
ext3 255 bytes
ext4 255 bytes
exFAT 255 UTF-16 characters
FAT32 255 UCS-2 code units with VFAT LFNs
NTFS 255 characters
BTRFS 255 bytes
ext3cow 255 bytes

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
Find Linux File Name Length
Find Linux File Name Length

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
Find Linux File Path Length
Find Linux File Path Length

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
File name too long Error
File name too long Error

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
Create File Name with Length
Create File Name with Length

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
List Linux File Name Limit Length
List Linux File Name Limit Length

You might also like to read related following articles:

We have understood how the filename length limit works in Linux and the implication of changing it.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.