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.
As @sergiy-kolodyazhnyy said, the maximum filename length will depend on the filesystem and the vast majority limit filename lengths to 255 bytes.
A notable omission from his chart is optical media. While UDF and the Rock Ridge extensions have the same 255-character limit for filenames, ISO9660 without Rock Ridge and Joliet both have much stricter limits that you may actually run up against if you're doing something like backing up
youtube-dl
downloads.Joliet filenames are limited to either 64 UTF-16 codepoints or 103 of them if your disc-mastering program has an option to break from the spec in ways which seem to cause no harm in practice.
Likewise, ISO 9660 Levels 2 & 3, without the Rock Ridge extensions, are limited to filenames of either 31 characters or 37 if you're playing fast and loose with the spec.
ISO 9660:1999, which is supported by genisoimage but not by frontends like K3b, has a limit of either 207 bytes (without Rock Ridge) or 197 bytes (with Rock Ridge).
(Source: The
genisoimage
manpage)As for the maximum path length, that's a big misconception. There isn't one for most Linux filesystems.
There's a constant named
PATH_MAX
, but it's only the maximum for certain POSIX APIs, which you can work around.The only consequential exceptions to this "no limit on path length" convention are FAT32 and exFAT (32,760 Unicode characters), NTFS and ReFS (32,767 Unicode characters), UDF (1,023 bytes), and ISO 9660 (unclear, but I've seen it stated as 180, 207, 212, or 222 bytes).
This can be easily demonstrated by running this small Python program and then exploring the resulting directories.
My
bash
, which displays the whole path in the prompt, will have trouble with it. However myzsh
, which displays only the current folder in the prompt will have no trouble and even has apwd
builtin that can display the entire 5000+-byte path without issue.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:
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:
From limits.h:
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