Are there any filename or path length limits on Linux?


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
  • 55
    answer is: limit is usually 255 chars (for those who are too lazy to click this link) – doc_id Sep 17 '12 at 15:04
  • 3
    @rahmanisback that's right for filename limits, while path limits are usually defined by the OS, not FS (except for some strange FSes like iso or ntfs), and, on linux, are 4K – nonchip Jun 27 '14 at 14:13
  • 3
    Actually it was about both :D – nonchip Jun 29 '14 at 1:14
  • 10
    Just pointing out: bytes != chars, especially if you use UTF-8. See here. – Kris Jun 5 '15 at 20:35
  • 3
    I'm shocked by these limits. Files per directory is unlimited, 4 billion files per volume, file sizes into the terabytes, volume sizes go to exabytes but we have a stupid limit of 255 bytes for file names? – jlh Sep 19 '17 at 19:14

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:


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.

  • 14
    Sorry, but I'am new here an can't even comment, save vote. The previous answer (by sfp) should be upped, as it answers the question completely, while the others are partially off. Again, sorry for going besides the rules, but I can't be quiet when the best answer is at the bottom. – David Balažic Jan 3 '12 at 23:56
  • 1
    Just pointing out: bytes != chars, especially if you use UTF-8. See here. – Kris Jun 5 '15 at 20:36
  • 2
    @DavidBalažic: Although true, PATH_MAX under linux is just a guideline, most of the underlying file systems do not have a limitation. This makes it hard to reference paths that greater than that size. I usually use "chunks" of PATH_MAX as a size. – Rahly May 30 '16 at 19:21
  • @Rahly Where do you use "chunks"? In a program? In a filesystem driver? – Melab Feb 20 at 20:02
  • either, but i'm talking about a program – Rahly Feb 22 at 10:51

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/
    $ getconf PATH_MAX /mnt/sda3/

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

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

  • 2
    Most programs are limited with absolute paths to PATH_MAX = 4096, though. That can be worked around if your program is able to use relative paths and you change your working directory first. – Mikko Rantalainen Feb 28 '18 at 10:50
  • 1
    It's because various POSIX APIs such as getcwd and realpath (which you can reimplement in userspace code by reading the metadata for . and then changing to .. and repeating until you hit the filesystem root) rely on PATH_MAX. (Source) – ssokolow Mar 13 '19 at 20:19
  • Yes, however, awfully lot of misc library code is prone to break if your code changes current directory at will. A well made code doesn't break but most of the existing code is not well made. – Mikko Rantalainen Feb 4 at 8:41

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

# define FILENAME_MAX 4096
  • So since the extX filesystems have a lower filename limit than what's defined in the kernel, you wouldn't ever hit that limit, unless it also encompases pathnames, right? – Ivan May 18 '09 at 18:33
  • 1
    that's what it looks like to me. There's also PATH_MAX for the path, which is 4096, so it would be hit before the "unlimited" path size on the exts... I'm not sure how the OS resolves its own internal restrictions and those of the FS, never had my arms in that deep. interesting question though. – jj33 May 18 '09 at 19:53
  • 4096 characters is a helluva path name. I'm sure it could be raised with a recompile, but honestly, /why would you need pathnames that long?/ – Avery Payne May 18 '09 at 23:52
  • I'm not sure you would need it or not. I view it more as a protection against malicious or negligent programs (I could easily see a script that behaves poorly and begins creating the same dir recursively. Actually, I've made that script, but it was redirecting a web site, not creating dirs...). – jj33 May 19 '09 at 12:12
  • @AveryPayne To add tags to files so they could be searched using a simple locate. – Hubert Kario Jun 18 '12 at 20:33

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

$ getconf PATH_MAX / 
$ getconf _POSIX_PATH_MAX / 

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.

  • A simple portable way to find the maximum length empirically is to write a program which creates longer and longer directory chains, and see where it fails. You won't know exactly why it fails (though you would hope for a suggestive human-readable error message) but you'll know how far you can safely go. Remember to check for both individual directory length, relative pathname length, and absolute pathname length. – tripleee Apr 12 '16 at 4:12
  • Also, e.g. the Python os.pathconf() module will have some answers; if the Python port is any good, they should be reasonable. – tripleee Apr 12 '16 at 4:14
  • 2
    You can't because some filesystems don't impose any limits. It would sooner fail with an out of memory error which any program would have a hard time recovering from. – Björn Lindqvist Apr 12 '16 at 14:46
  • This is the correct answer, except this is due to @BjörnLindqvist comment. PATH_MAX is just a guideline, and 99% of files will probably be within that limit. – Rahly May 30 '16 at 19:25

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.


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' {}


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.