Having used Windows systems for a long time, I know that at a certain point, an error window can appear when files and folder names become too long.

This happened to me when I tried to backup files with SFTP from a server to a folder in (for example):

D:(Windows drive partition)/Temporary/Projects/2015-06/Websites/Guitar-Site/Images/Logos/Manufacturers/Instruments/Basses/(long file name).png

As you can see, I tend to build very specified folder paths sometimes and if a file name happens to be long as well, NTFS might not be able to save it this way.

I'm currently worrying about my physical backups, as the folder path on my backup drive will add /backups/(drive name)/... to all file paths.

Is there any such limit (or a similar one) in ext4/Ubuntu that I would have to look out for?


The max filename length is 255 bytes. Found in the wiki page for ext4.

And a maximum path of 4096 characters. Found in this Unix&Linux SE Question.

Although, I did find this wiki article that does not specify a max file path in ext4.

  • Hi jtoscarson, thanks for your answer. I could probably try to look this up, but would you care to explain what a length of "255 bytes" means? I assume that not all characters necessarily use up 8 bits, so that would be more than 255 characters in total, I assume? Or maybe less, considering different charactersets could be used. – Prototype700 Dec 12 '16 at 21:05
  • Generally speaking a single character is one byte. I didn't look for the documentation, but here is a simple test: jtoscarson@Tylers-Ubuntu:~$ echo "123abc" | wc -c 7 jtoscarson@Tylers-Ubuntu:~$ echo "123abc" | wc -m 7 The -m is counting characters and the -c is counting bytes. The reason why it is 7 instead of 6 is the end of line character which is not printed. So the total characters in the filename is going to be 255. – jtoscarson Dec 12 '16 at 21:43
  • 1
    Using UTF-8 locale returns 4 for echo -n "💩" | wc -c. Creating a filename called with that name would take 4 bytes despite the fact that this filename is 1 grapheme long. A "character" is not clearly defined concept (usually it means byte, grapheme or UNICODE code point). – Mikko Rantalainen Feb 28 '18 at 11:02
  • On encrypted filesystems the max filename length is 143 bytes. To decide whether a filename is short enough you can find his byte length in Python with len(filename.encode()). – Marvo Mar 9 '18 at 12:45

I believe that the most reliable way to determine this is with the pathconf(".", _PC_PATH_MAX); POSIX function, which determines the maximum path for a given path.

As the function suggests, this can vary between filesystems.

I don't know of a command line utility that exposes it though. Here is a minimal C example: https://stackoverflow.com/questions/16285623/how-to-get-the-to-get-path-to-the-current-file-pwd-in-linux-from-c/54155296#54155296


The pathname limits depend on filesystem in use. jtoscarson's answer covers ext4 which is default on Ubuntu, however you can use variety of filesystems on Ubuntu. To cite WerkkreW answer on serverfault, here are some of the filesystems and their limits:

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

Note also that various filesystems have limitations as to which type of character can be present in filename. For instance, filenames in ext4 cannot contain NULL and /. See also, Wikipedia article for filesystem comparisons.

Note also that Linux filesystems have to take into consideration POSIX definitions:

3.266 Pathname

A character string that is used to identify a file. In the context of IEEE Std 1003.1-2001, a pathname consists of, at most, {PATH_MAX} bytes, including the terminating null byte. It has an optional beginning slash, followed by zero or more filenames separated by slashes. A pathname may optionally contain one or more trailing slashes. Multiple successive slashes are considered to be the same as one slash.

From limits.h:


Maximum number of bytes in a pathname, including the terminating null character. Minimum Acceptable Value: {_POSIX_PATH_MAX}


Maximum number of bytes in a pathname. Value: 256

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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