Are there any filename or path length limits on Linux?
asked May 18, 2009 at 17:27
2
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,4402 gold badges12 silver badges26 bronze badges
answered May 18, 2009 at 17:29
WerkkreWWerkkreW
5,9093 gold badges23 silver badges32 bronze badges
11
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
26k7 gold badges59 silver badges90 bronze badges
answered Aug 31, 2011 at 8:58
sfpsfp
1,1211 gold badge7 silver badges2 bronze badges
5
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 :
- file-system limits as stated by WerkkreW ;
- constants defined in
linux/limits.h
as stated by sfp.
To dynamically get these properties:
- Use functions
pathconf
andfpathconf
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
answered May 24, 2014 at 7:35
oHooHo
5251 gold badge6 silver badges14 bronze badges
1
And for the sake of saving time [and anchoring it to memory]:
ext2, ext3, ext4, zfs: no pathname limits; 255 bytes filename limit.
3
Those are file system name lengths. "linux" itself has some too. For instance, from bits/stdio_lim.h:
# define FILENAME_MAX 4096
answered May 18, 2009 at 18:15
jj33jj33
11k1 gold badge36 silver badges50 bronze badges
9
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.
answered Mar 22, 2016 at 18:31
4
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.
answered Jan 16, 2015 at 2:17
andyandy
1212 bronze badges
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 */
...
answered Dec 5, 2014 at 1:49