How long can be files names and folder names in Ubuntu Linux and what characters are allowed in file name and folder name in Ubuntu Linux?
2 Answers
File names in Linux were 14 bytes long in earlier Unix version. But The modern Linux system has 255 bytes for file names.
As a character requires 1 byte, The length becomes 255 characters. Also the folders are treated as files in Linux system
See this link for more information
- 75,875
- 31
- 191
- 309
-
2File names are utf-8, so variable length: one byte for any ascii character. 2 or more for any other character e.g. £, ★, ≠, ☺, ¡, ¿, á, …, etc – ctrl-alt-delor Jul 11 '16 at 08:23
-
1If filename is in UTF encoding , the amount of characters decreases with higher number of UTF encoding. See http://serverfault.com/a/542452/363611 and the comment below that answer – Sergiy Kolodyazhnyy Aug 02 '16 at 01:13
I'm not sure what the maximum file name length can be (for ext4), but it's more dependent on the file system, than Linux itself. On FAT32, I think it is 255 characters. You probably don't ever actually need a file name that long.
As for characters allowed, any byte value is allowed on the ext4 file system, except for the NULL byte (and /, as that is the directory separator1). However, you should limit your file names to the UTF-8 character set, for the widest range of compatibility across applications, and devices.
1. As stated in the glibc manual, "any character except the null character is permitted in a file name string," but a / in the file name string separates the name of one file or folder from that of its parent.
- 116,445
- 54
- 318
- 493
- 40,344
- 5
- 56
- 98
-
I'ld say limit to a-z,A-Z,and numbers. Adding non-alpha-numerics is begging to find url parsing bugs – RobotHumans Jul 22 '12 at 16:40
-
-
'.' is of course fine. I haven't seen @ go wooly, but I guess it could in some corner case. Things parsers use as delimiters and don't escape properly is more what I was referring to - examples: space, /, ", ', etc – RobotHumans Jul 22 '12 at 16:57
-
1The period `.` is widely used in the system itself, so it is not a problem. The `@` should also be fine, I see email servers (e.g. `exim`) with one directory per account that contain `@` and have no problem whatsoever. – Marios Zindilis Jul 22 '12 at 16:58
-
1using a @ is fine. 2 remarks: IF you use something special you can always escape the char. Also do realize that sometimes a char is used as a divider: for instance ssh uses it to seperate user and system: example this: `user@system:/dir/dir@dir/` might be iffy and not understood). – Rinzwind Jul 22 '12 at 17:02
-
@dobey When you recommend to "limit your file names to the UTF-8 character set," what do you mean? Every possible Unicode character can be expressed in UTF-8 (some just take multiple bytes). Do you mean you recommend limiting file names to contain only characters that are 1 byte long in UTF-8? – Eliah Kagan Jul 22 '12 at 17:09
-
@EliahKagan answer me this: what would happen if you send a file to someone else? that is why you should stick with utf-8 (and for what it matters I would stick with the basic 104 chars ;) ) – Rinzwind Jul 22 '12 at 17:10
-
@Rinzwind But as I said, *all Unicode strings can be encoded in UTF-8, so what does that mean*? To answer your question though: If a filename contains unusual characters not supported by another filesystem, usually nothing very bad happens when it's moved to the new filesystem. The filename may get messed up. On the other hand, filenames with characters like backslash and `:` often fail completely to transfer. In every character set I'm aware of, backslash and `:` can be expressed in the simplest possible way (particularly, in multi-byte character sets, always with a single byte). – Eliah Kagan Jul 22 '12 at 17:13
-
well I had troubles with turkish files 1/2 a year back. They have this weird i and it messed up commandline traversing :( That's why I got into this topic but if it is as you say it should not be a problem ;) – Rinzwind Jul 22 '12 at 17:18
-
@EliahKagan No, I mean using UTF-8 instead of say ISO8859-15, or KOI8-R and such, for accented, or non-latin characters. – dobey Jul 22 '12 at 17:41
-
to be clear, with my earlier statement, i didn't mean in your app specifically. it's irritating when you try and share something across apps and app X parses it fine, but app Y explodes because they anticipated utf or failed to parse delimiters properly. i should find an example... https://launchpad.net/+search?field.text=space+in+folder+name – RobotHumans Jul 22 '12 at 17:57