197

Are there any filename or path length limits on Linux?

yanychar
  • 103
readonly
  • 3,579

8 Answers8

191

See the Wikipedia page about file systems comparison, especially in column Maximum filename length.

Here are some filename length limits in popular file systems:

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
XFS     255 bytes
Jens Erat
  • 1,743
WerkkreW
  • 6,129
128

I've read here that path length limit is in system headers. File name length limit is there too. On my system it's file:

  /usr/src/linux-headers-2.6.38-10/include/linux/limits.h

and C-lang defines:

  #define NAME_MAX         255    /* # chars in a file name */
  #define PATH_MAX        4096    /* # chars in a path name including nul */

and some more.

Ladadadada
  • 27,207
sfp
  • 1,281
37

I refer to other answers, please upvote them.

Are there any filename or path length limits on Linux?

Yes, filename and pathname lengths are limited by :

To dynamically get these properties:

  • Use functions pathconf and fpathconf as proposed by Michael Aaron Safyan
  • Create a filename (or pathname) longer and longer as explained by dogbane
  • Use the command getconf as proposed by tim that is also available on Linux:

    $ getconf NAME_MAX /mnt/sda2/
    255
    $ getconf PATH_MAX /mnt/sda3/
    4096
    
oHo
  • 595
21

And for the sake of saving time (and anchoring it to memory):

ext2, ext3, ext4, zfs: no pathname limits; 255 bytes filename limit.

Ivan
  • 3,202
8

Those are file system name lengths. "linux" itself has some too. For instance, from bits/stdio_lim.h:

# define FILENAME_MAX 4096
jj33
  • 11,388
4

There is no way to determine the maximum length of paths on Linux in a portable way. On my system:

$ getconf PATH_MAX / 
4096
$ getconf _POSIX_PATH_MAX / 
4096

But I can easily create paths much longer than 4096 characters. Instead see PATH_MAX as a lower bound. You are guaranteed to be able to create paths this long, but you might also be able to create much longer ones.

2

You should always use pathconf or some function like this to get the runtime value about the specified items, as this page said that:

It should be noted, however, that many of the listed limits are not invariant, and at runtime, the value of the limit may differ from those given in this header, for the following reasons:

  • The limit is pathname-dependent.

  • The limit differs between the compile and runtime machines.

For these reasons, an application may use the fpathconf(), pathconf(), and sysconf() functions to determine the actual value of a limit at runtime.

andy
  • 121
0

It's specified in the system limits.h header file.

Here is one of these files:

cat /usr/include/linux/limits.h

...
#define NAME_MAX         255    /* # chars in a file name */
#define PATH_MAX        4096    /* # chars in a path name including nul */
...

Here is where copies of this file are located and values they define:

find /usr | grep limits.h | xargs -I {} grep -H 'NAME_MAX' {}

Output:

...
/usr/include/linux/limits.h:#define NAME_MAX         255        /* # chars in a file name */
...