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.
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:
See the Wikipedia page about file systems comparison, especially in column Maximum filename length.
Here are some filename length limits in popular file systems:
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:
and some more.
I refer to other answers, please upvote them.
Yes, filename and pathname lengths are limited by :
linux/limits.h
as stated by sfp.To dynamically get these properties:
pathconf
andfpathconf
as proposed by Michael Aaron SafyanUse the command
getconf
as proposed by tim that is also available on Linux:And for the sake of saving time (and anchoring it to memory):
ext2, ext3, ext4, zfs: no pathname limits; 255 bytes filename limit.
Those are file system name lengths. "linux" itself has some too. For instance, from bits/stdio_lim.h:
There is no way to determine the maximum length of paths on Linux in a portable way. On my system:
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.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's specified in the system limits.h header file.
Here is one of these files:
Here is where copies of this file are located and values they define:
Output: